如何使用Windows身份验证和自定义角色提供程序设置OWIN

bat*_*uip 12 authentication roleprovider windows-identity owin asp.net-mvc-5

在MVC4中,我<authentication mode="Windows"/>在web.config中启用并创建了一个自定义角色提供程序,然后自动为您包装WindowsIdentitya RolePrincipal.工作就像一个魅力.

你会如何使用OWIN和/或Microsoft.ASPNET.Identity在MVC5中执行此操作?

jd4*_*d4u 10

它在web.config中配置或在IIS网站上配置的方式类似.

<authentication mode="Windows" />
<authorization>
  <deny users="?" />
</authorization>
Run Code Online (Sandbox Code Playgroud)

以上内容适用于Intranet.对于其他方案(如提供其他声明转换以及混合身份验证),对于ASP.NET应用程序,您可以使用自定义OWIN中间件处理程序.

看看这样的WindowsPrincipalHandler的例子.你需要在startup.cs中注册它app.Use(typeof(WindowsPrincipalHandler))