Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post May 22, 2012 03:54 AM by Steven Cheng - MSFT
May 21, 2012 12:12 PM|LINK
I want to access the login name of a user who is currently logged in my program and store this information in a database. How do I do this? I currently use login controls (such as loginview, etc.).
May 21, 2012 12:15 PM|LINK
dtore the username in sessions which can be accessable throught the application
May 21, 2012 12:25 PM|LINK
How do I do that?
May 21, 2012 12:26 PM|LINK
May 21, 2012 05:24 PM|LINK
Yes its right way to get the username of the logged-in user from the login control based authentication. Follow the same.
May 22, 2012 03:54 AM|LINK
As Mudasir.Khan suggested, you can use HttpContext.Current.User.Identity to get the authenticated user information. And this works if you're using ASP.NET built-in authentication methods (such as Windows, Forms authentications) for your web application.
So when using built-in forms authentication, after user logon via the login.aspx page, the authenticated user identity info is stored in cookie and available through the HttpContext.Current object.
#Explained: Forms Authentication in ASP.NET 2.0
If you use your custom forms authentication such as manually do the username/password validation and use a session variable to mark the authentication status of current request, then you need to use your custom code logic to determine current user.
BTW, if you have interests, you can use reflector tool to inspect how the LoginView or LoginName control is implemented for more ideas.