繁体   English   中英

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

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

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

您所需要做的就是实现Userstore for 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
}

然后将每个请求将MyUserStore传递到UserManager

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

您可以从GitHub上的以下项目中获取UserStore.cs模板,并根据需要对其进行调整,这将使您摆脱对Microsoft.AspNet.Identity.EntityFramework的依赖。

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

(免责声明:我是该项目模板的作者)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM