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

三世轮回 提交于 2019-12-09 09:30:48

问题


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.


回答1:


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();



回答2:


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?




回答3:


You can get the user id with

User.Identity.GetUserId()


来源:https://stackoverflow.com/questions/19178218/switch-from-old-asp-net-membership-to-asp-net-identity-visual-studio-2013

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!