Solved

Access User Name in application

Posted on 2010-08-15
7
349 Views
Last Modified: 2013-11-12
Hi All,

I need to obtain the log in information of a user using an asp.net forms authentication log in control and get that information within a silverlight application. How would i do this?

currently once logged in i have:
FormsAuthentication.RedirectFromLoginPage(LoginUser.UserName, true);
FormsAuthentication.SetAuthCookie(LoginUser.UserName, false);

I do not want to use query string as i am using forms authentication and was now wondering how to access the UserName from the cookie within the silverlight application

thanks

baz
0
Comment
Question by:baz86
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 22

Expert Comment

by:Mrunal
ID: 33442973
0
 
LVL 8

Expert Comment

by:WesWilson
ID: 33457391
Profile.UserName gives you read access to the logged-in user's UserName.
0
 

Author Comment

by:baz86
ID: 33457849
Hi WesWilson, I can't get access to Profile.UserName from my silverlight app. The actual log in is done using asp.net controls but I want to be able to access the signed in user and use that user info as parameters in my silverlight controls.

Do you have any idea on how i could do this?
0
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
LVL 8

Accepted Solution

by:
WesWilson earned 500 total points
ID: 33458061
You can store your username in the Session:

Session.Add("UserName", LoginUser.UserName);

And then to access it from Silverlight, there are three different options mentioned here:
http://www.dotnetspider.com/tutorials/Silverlight-Tutorial-316.aspx

A tutorial on the best option (option 3) is available here: http://www.codeproject.com/KB/silverlight/SilverlightASPNetSessions.aspx
0
 

Author Comment

by:baz86
ID: 33459386
I have looked at the suggested link and tried it by creating a session once a user logs in :

FormsAuthentication.RedirectFromLoginPage(LoginUser.UserName, true);
FormsAuthentication.SetAuthCookie(LoginUser.UserName, false);
Session["userinformation"] = LoginUser.UserName;  
and then create a wcf data service that returns the session information like so:

public object getSessionDetails()
{
return System.Web.HttpContext.Current.Session["userinformation"];
}
 
but I get a NullReferenceException: Object reference not set to an instance of an object.
Any thoughts on how i can get this working?
0
 

Author Comment

by:baz86
ID: 33459935
Hi,
 
In the _service.svc.cs file I put

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
and this seemed to fix the error that I was getting that the state was not getting preserved. But now I have the issue that none of the [OperationContracts] are executing. If i comment out the CompatibilityRequirements, the WCF web methods seem to run ok but i get the same NullReference error in the web method that gets the session details.
I feel im so close to using sessionand also running the WCF queries using the information from the session, but this last bit seems to be hindering me. Could you please help.
Thanks!
0
 

Author Closing Comment

by:baz86
ID: 33468928
This was the correct solution for the question. I never thought of using sessions and seems like using it to access userinformation using sessions is the best way
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How do I hide MVVM menu items in WPF/XAML? 1 33
C# Linq - Join two objects into one 3 31
Problem to Office 1 42
"The resource cannot be found" 1 24
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question