How to migrate from Forms Authentication to ASP .NET Identity

爱⌒轻易说出口 提交于 2019-12-07 23:22:43

问题


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 ?

Edit:

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

User Table

UserId

UserName

Password

UserTypeId

User Type Table

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.


回答1:


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

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:

  • 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).

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.

Hope it helps :)



来源:https://stackoverflow.com/questions/36078322/how-to-migrate-from-forms-authentication-to-asp-net-identity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!