ASP.NET MVC 5 OWIN Auhentication [英] ASP.NET MVC 5 OWIN Auhentication
问题描述
我刚开始知道MVC 5,我尝试使用其内置的owin认证。
I have just started to know the MVC 5 and I am trying to use its built in owin authentication.
我需要实现与IIS窗体身份验证,但OWIN认证是复杂得多,我等待着。
I need to implement a forms authentication with IIS, but the OWIN Authentication is complicated than i waited.
我有AZ实体框架模型自己的用户,角色和RoleUser表,并希望通过这些表来认证用户。
I have az Entity Framework Model with own User, Role and RoleUser tables and want to authenticate user by these tables.
我试图理解了它的owin是如何工作的一个样本MVC 5应用程序。它有一个ApplicationUser类:
I tried to figured it out, how the owin works on a sample mvc 5 application. It has an ApplicationUser class:
public class ApplicationUser : IdentityUser
{
}
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection")
{
}
}
我的主要问题是IdentityUser。这是一个自己的ASP.NET用户类实现IUSER接口的DbContext的连接。我从EF模型中自己的用户POCO实体,我不想把它与一个ASP.NET IUSER接口混用。我不知道为什么,但IUSER接口ID为字符串类型,这也并不适用于我。
My main problem is the IdentityUser. It is an own ASP.NET User class with implementation of IUser interface and connection of DbContext. I have an own User POCO entity from the EF model and i do not want to mix it with an ASP.NET IUser interface. I do know why, but the Id of IUser interface is string type, that is also not apply to me.
在owin异步用户登录如下:
The owin async user sign in is the following:
private async Task SignInUserAsync(User user, bool isPersistent)
{
AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
ClaimsIdentity identity = await UserManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie);
AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = isPersistent }, identity);
}
它建议建立身份的ClaimsIdentity类型的用户登录,用户属性必须实现IUSER接口。
It recommends to create a ClaimsIdentity type of identity to sign in user and the user property must implements IUser interface.
大问题:是对欧文提出在我的环境中使用?我想用我的用户类别与owin身份验证,但我不知道怎么样?
Big question: Is the owen suggested to use in my environment? I want to use my User Class with owin authentication, but i don't know how?
感谢您的帮助提前!
推荐答案
您可以沟整个ASP.NET身份模型,并用自己的组件进行密码验证和角色/索赔存储。
You can ditch the entire ASP.NET Identity model and use your own components for password verification and roles/claim storage.
的http://www.khalidabuhakmeh.com/asp-net-mvc-5-authentication-breakdown-part-deux
会员/身份和窗体身份验证的标识和访问管理的两个不同的功能。微软文档没有做好解释两者之间的区别。这是一个短暂的甜蜜后,解释它。这篇文章是OWIN之前写的,但同样的原则也适用。
Membership/Identity and Forms Auth are two different features of id and access management. Microsoft documentation does not do a good job explaining the difference between the two. This is a short and sweet post that explains it. The article was written before OWIN, but the same principle applies.
的http://brockallen.com/2012/06/04/membership-is-not-the-same-as-forms-authentication/
这篇关于ASP.NET MVC 5 OWIN Auhentication的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!