Custom Asp.net mvc 5 authentication without using Microsoft.AspNet.Identity.EntityFramework

安稳与你 提交于 2019-12-22 05:33:28

问题


How do you create a custom ASP.NET MVC 5 Auth without using the UserStore of Microsoft.AspNet.Identity.EntityFramework??


回答1:


All you have to do is implement the same interfaces that the Userstore for Identity.Entityframework uses.

User will be your user class

public class MyUserStore<TUser> : 
    IUserLoginStore<TUser, int>, 
    IUserClaimStore<TUser, int>, 
    IUserRoleStore<TUser, int>, 
    IUserPasswordStore<TUser, int>, 
    IUserSecurityStampStore<TUser, int>, 
    IUserStore<TUser, int>, 
    IDisposable where TUser : User
{
   //Implement the interfaces you need
}

Then pass your MyUserStore into the UserManager each request

new UserManager<User, int>(new MyUserStore<User>(new MyContext()))



回答2:


You can grab UserStore.cs template from the following project on GitHub and tweak it as you like, it will allow you to get rid of the dependency on Microsoft.AspNet.Identity.EntityFramework.

https://github.com/kriasoft/AspNet-Server-Template -> ./src/App.Server/Data/UserStore.cs

(disclaimer: I'm the author of this project template)



来源:https://stackoverflow.com/questions/25488716/custom-asp-net-mvc-5-authentication-without-using-microsoft-aspnet-identity-enti

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