简体   繁体   中英

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

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

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

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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