如何从表单身份验证迁移到ASP .NET Identity [英] How to migrate from Forms Authentication to ASP .NET Identity

查看:99
本文介绍了如何从表单身份验证迁移到ASP .NET Identity的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个既包含常规MVC控制器又包含Web API控制器的MVC项目中.最初,我使用自定义用户表实现了表单身份验证.但是,现在我计划使用新的ASP .NET身份,并从基于表单cookie的身份验证更改为基于声明的身份验证和授权.我已经有一个带有自定义字段表的数据库.因此,我需要自定义ASP.NET身份以与我的表一起使用 谁能指导我如何实现这一目标?

I am working in a MVC project that contains both regular MVC controllers as well as Web API Controllers. Initially I implemented Forms Authentication with custom user table. But now I am planning to use the new ASP .NET Identity and change from the forms cookie based authentication to claims based authentication and authorization. I already have a database with tables with custom fields. So I need to customize the ASP .NET Identity to work with my tables Can anyone guide me on how this can be achieved ?

作为对FKutsche的答复,这是我拥有的User表.我只保留了重要的列.

In reply to FKutsche, here is the User table that I have. I have kept only the columns that matter.

用户表

UserId

用户名

密码

UserTypeId

UserTypeId

用户类型表

UserTypeId

UserTypeId

UserType

列名是不言自明的,因此在此不再赘述.用户表在UserTypeId列上具有指向UserType表的外键.

The column names are self explanatory so I am not describing them. The User Table has foreign key on UserTypeId column to the UserType table.

推荐答案

如果您不打算使用身份表格式,则进行这种迁移是没有意义的.

There's no point in making this kind of migration if you're not going to use the Identity table format.

ASP.NET Identity具有出色的现成功能,如果没有适当的数据库支持(用户表无法提供这些功能),这些功能就无法存在.

ASP.NET Identity has an outstanding out-of-the-box list of features that simply cannot exist without the appropriate db support (and that user table is not capable of providing them).

我认为您在这里有不同的选择:

I think you have different options here:

  • 坚持使用用户表并在其上构建自定义oauth提供程序(这不太困难,请检查此这样的答案.
  • stick with your user table and build a custom oauth provider on it (it's not too difficult, please check this link - I personally built the security layer of many apps following this guide)
  • migrate to a brand new identity model with ASP.NET identity and link this table as an extended claim to the IClaimsIdentity generated for the logged user (check this SO answer for example).

恕我直言,我个人更喜欢第二种选择:您必须将用户ID和密码迁移到新系统,但是最好从可靠且经过良好测试的东西开始.这样,您还可以访问将来的改进,而对于无需大量编码工作的完全定制的系统来说,这可能是不正确的.

IMHO, I personally prefer the second option: you have to migrate your user ids and passwords to the new system, but it's better to start with something solid and well tested. This way you will also have access to future improvements, which is probably not true with a completely customized system without a big coding effort.

希望它会有所帮助:)

这篇关于如何从表单身份验证迁移到ASP .NET Identity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆