I’ve read that question on many message boards so I decided to post a quick blog entry about that. It’s actually very easy.
If you use the new comfortable Login Controls of ASP.NET v2, here is how you resolve the UserID of the currently logged in user:
MembershipUser myObject = Membership.GetUser();
string UserID = myObject.ProviderUserKey.ToString();
That’s all! Hope that helps..
60 comments ↓
Thanks alot, until now I have retrieved it from the user table, but why not use the inbuild methods đŸ™‚
I found it.
Just want to share it with you if somebody needs it:
First have to convert the string to Guid and the to call the method:
Guid UserID = new Guid(“57b0c146-9b75-433b-a6ac-30b598bdbbef”);
Label1.Text= Membership.GetUser(UserID).UserName.ToString();
Good luck
Thanks heaps!
Fantastic and easy (just the way I like it).
I have to agree with Lulu (Comment 38), ASP.NET forums were less than helpful.
You saved my bacon!
Cheers,
Super nice post.!
And you better believe that this post helps ;o)
Yep, a real time saver and simple too.
Thanks
Beautiful! Posted so long ago and still helped me with ASP.NET 4.0 in MVC3. Thank you!
I Love you
hi guys:
when i need use userid foreign key in other tables in my application set userid datatype string or uniqueidentifier
Thanks!
my_aspnet_membership does not contain a definition for GetUser(). Am I missing something? I am using MySQL Connector/NET .
Thanks
Leave a Comment