Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Access User Name in application

Posted on 2010-08-15
7
Medium Priority
?
352 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 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
DFW AZURE MEETUP TONIGHT FRI 6PM

We will be discussing what Azure Stack is, how does it fit into the suit of offerings that Azure has currently, and where can it fit into your organizations technology stack. We will also be discussing limitations of the platform while covering various applicable scenarios.

 
LVL 8

Accepted Solution

by:
WesWilson earned 2000 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

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:…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

705 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