Switch from old ASP.NET Membership to ASP.NET identity (Visual Studio 2013)

asp.netasp.net-identityforms-authentication

Introducing ASP.NET Identity – A membership system for ASP.NET applications

http://blogs.msdn.com/b/webdev/archive/2013/06/27/introducing-asp-net-identity-membership-system-for-asp-net-applications.aspx

Now when creating a new web application with ASP.NET 4.5, we have the new "ASP.NET Identity".

I manage to let my application to use my MSSQL database with the build in register/login/change password functions, but I am not sure how to do other operation like old days ( especially the "ASP.NET Configuration" is gone). Since this is something new, I failed to find any nice guide or I was thinking wrongly.

  1. the "[dbo].[AspNetUsers]" now has the [Id] in nvarchar(128), not the uniqidentifier, but still in GUID format
  2. Membership.GetUser().ProviderUserKey is no longer working, how do I get the Id? (get username by User.Identity.Name then query the [dbo].[AspNetUsers]?"
  3. How to create (manage) roles beside manipulate the database directly? (like the previous System.Web.Security.Roles.CreateRole method)

etc

it would be best if anyone can provide link for a detail introduction about how to implement this "ASP.NET Identity"

Thanks a lot..

Update

I found the Id can be retrived by:
(new System.Linq.SystemCore_EnumerableDebugView(((System.Security.Claims.ClaimsPrincipal)(((System.Web.UI.Page)(this)).User)).Claims)).Items[0].Value

it is in the claim.. but looks not very efficient.

Best Answer

I'm in the same boat. I have found a cleaner way to get the userid

 var identity = new ClaimsIdentity(User.Identity);
 var id = identity.GetUserId();
Related Topic