Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 513
Yiping Avatar asked Oct 04 '13 09:10

Yiping


2 Answers

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();
like image 60
Diver Dan Avatar answered Nov 09 '22 06:11

Diver Dan


As of .net 4.5 all identity based information is returned as a claims based object. This looks to be an updated version of the simple identity provider that is found in the asp.net MVC template for "Internet Application" if you are using visual studio 2012. As to the link that you reference there is also a sample project that should get you started https://github.com/rustd/AspnetIdentitySample Were you having specific issues beyond this?

like image 38
Mike Beeler Avatar answered Nov 09 '22 07:11

Mike Beeler