自定义Asp.net mvc 5身份验证,不使用Microsoft.AspNet.Identity.EntityFramework

Joh*_* Po 6 c# asp.net asp.net-mvc owin asp.net-mvc-5

如何在不使用Microsoft.AspNet.Identity.EntityFramework的UserStore的情况下创建自定义ASP.NET MVC 5 Auth?

Sho*_*hoe 2

您所要做的就是实现用户存储所Identity.Entityframework使用的相同接口。

User将是您的用户类别

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
}
Run Code Online (Sandbox Code Playgroud)

然后将您的传递到每个请求MyUserStoreUserManager

new UserManager<User, int>(new MyUserStore<User>(new MyContext()))
Run Code Online (Sandbox Code Playgroud)