How can I access UserId in ASP.NET Membership without using Membership.GetUser()?

GrZeCh picture GrZeCh · Sep 29, 2008 · Viewed 47.6k times · Source

How can I access UserId in ASP.NET Membership without using Membership.GetUser(username) in ASP.NET Web Application Project?

Can UserId be included in Profile namespace next to UserName (System.Web.Profile.ProfileBase)?

Answer

Sandeep Kumar picture Sandeep Kumar · Jan 6, 2009

Try this:

MembershipUser CurrentUser = Membership.GetUser(User.Identity.Name);
Response.Write("CurrentUser ID :: " + CurrentUser.ProviderUserKey);