Solved

Access User Name in application

Posted on 2010-08-15
7
345 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
  • 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

747 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now