我在带有 OWIN 的 ASP.NET MVC 5 应用程序中使用 ASP.NET Identity 2。到目前为止,如果经过身份验证的用户尝试访问他没有角色的操作,他将被重定向到登录页面。在这种情况下,如何使经过身份验证的用户获得 AccessDenied 页面,但未经身份验证的用户仍会被发送到登录页面?
ConfigureAuth 方法如下:
public void ConfigureAuth(IAppBuilder app)
{
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider
{
}
});
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
app.UseSaml2Authentication(GetSamlOptions());
}