Reputation: 71
I'm relatively new to asp.net and c#, but have learned a ton in the past few months. My question probably has a relatively simple solution, but it's escaping me.
I currently have a site setup with user registration and authentication through the standard asp.net membership tables. I'm trying to create a "My Account" page that users can go to when logged in that will display information about their accounts pulled from other tables.
How do I indicate the logged in "UserName" value as the input parameter for the account information tables that I need to query?
Thanks
Upvotes: 0
Views: 907
Reputation: 25356
If you're using .NET Membership Provider, you can get info about currently logged in user by doing the following:
MembershipUser user = Membership.GetUser();
Guid userID = (Guid)user.ProviderUserKey;
string username = user.UserName;
EDIT: I guess it is overkill to use Membership.GetUser() if only thing you need is UserName. Use HttpContext.Current.User.Identity.Name as others suggests if UserName is the only thing you need.
Upvotes: 2
Reputation: 29157
http://msdn.microsoft.com/en-us/library/system.web.httpcontext.user.aspx. The Name property is the one you want.
Upvotes: 1
Reputation: 3963
try User.identity.name
httpcontext.current.user.identity.name
Upvotes: 1