views:

306

answers:

4

Hi,

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

+1  A: 

try User.identity.name

httpcontext.current.user.identity.name
BigBlondeViking
A: 

HttpContext.Current.User.Identity.Name

Erich
Got it! Thanks everyone.
MGumbel
+1  A: 

http://msdn.microsoft.com/en-us/library/system.web.httpcontext.user.aspx. The Name property is the one you want.

RichardOD
+2  A: 

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.

Brian Kim