新的 ASP.NET MVC 标识框架是否在没有实体框架和 SQL Server 的情况下工作?

我是 ASP.NET MVC 5 的新手,所以我正在尝试尽可能多地使用它来通过实践来学习它.

I am new to ASP.NET MVC 5 and so I am trying to use it as much as possible to learn it by practice.

所以我在考虑使用ASP.NET MVC的新的OWIN实现来实现我的项目的认证和授权.也就是说,我正在以一种可以与各种类型的数据库一起工作的方式构建该项目.

So I am thinking of using the new OWIN implementation of ASP.NET MVC to implement the authentication and authorization of my project. That said, I am building the project in a way that it can work with various types of databases.

到目前为止,我已经使用了通用的 ADO.NET 元素(例如 DbDataReader 等)并且我拒绝使用任何 ORM.所以我想知道我是否可以继续使用 ASP.NET 的新标识系统,或者如果我这样做,我是否会绑定到实体框架和 SQL Server?

So far I have used generic ADO.NET elements (e.g. DbDataReader etc) and I have refused to use any ORM. So I am wondering if I can go ahead with using the new identity system of ASP.NET or will I be bound to Entity Framework and SQL Server if I do so?

推荐答案

没那么简单.也没有那么难.

Not that simple. Not that hard either.

您必须编写以下自定义实现:

You'll have to write your custom implementation of:

  1. IUserStore
  2. IUserPasswordStore
  3. IUserTwoFactorStore
  4. IUserClaimStore
  5. IRoleStore
  6. IUserSecurityStampStore
  7. IUserRoleStore
  8. UserManager

然后从IUser创建您自己的用户实现,例如:

Then create your own user implementation, from IUser<TKey>, like:

public class MyUser : IUser<string>
{
    public string Id { get; set; }
    public string UserName { get; set; }
}

最后,从 NuGet 中删除 AspNet.Identity.EntityFramework,如果您不在其他地方使用它,它也会删除 EntityFramework.

Finally, from NuGet, remove AspNet.Identity.EntityFramework, which will remove EntityFramework too if you're not using it elsewhere.

无论您的代码在哪里出错,都要重写它以使用您的自定义实现.

Wherever your code breaks, rewrite it to use your custom implementations.

创建一个实现从 1 到 7 项的 MyUserRepository.

Create a MyUserRepository which implements items from 1 to 7.

然后,创建一个实现第 8 项的 MyUserManager.

Then, create a MyUserManager which implements item 8.

将它连接起来代替默认的 AspNet.Identity.EntityFramework 类非常容易.

It will be damn easy to wire that up in place of default AspNet.Identity.EntityFramework classes.

相关文章