Tutorial :aspnet_users: get user id and use id web page



Question:

As I create user using built in asp.net sql tables and login controls, I would like to get to userid. How do I do that? Google is returning whole bunch of information but no where I could find an easy example to get UserID.

If user does exist, then I should get a userid, which I could store in my own custom tables for further user personal information management.

This whole membership and profile thing is very confusing to me. Google returned resuilts have all these pages with long explanation but it only confuses me. I can not even find the namespace in some of those dumb examples.

You can tell I am frustrated.

Please help !!!


Solution:1

This will give you the MembershipUser for the current logged in user

MembershipUser currentUser = Membership.GetUser(True)  

From that you would use the ProviderUserKey property to get provider specific identifier. This is an object, so, assuming SqlMembershipProvider you need to cast it to a GUID. You can then use that in your tables.


Solution:2

You're looking for information on Forms Authentication.

The answer to your specific question is via HttpContext.Current.User. The Page class has a property named User which wraps HttpContext.

If HttpContext.Current.User.Identity.IsAuthenticated Then      Dim userName As String = HttpContext.Current.User.Identity.Name      ' ...   End If  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »