【发布时间】:2018-07-06 02:21:41
【问题描述】:
我正在开发一个 ASP.NET Core 2 Web 应用程序。我正在处理 [授权(角色或策略)] 页面的“拒绝访问”页面。
默认情况下,ASP.NET Core 2.0 不会显示原始 URL 并返回 403 状态,而是将请求重定向到状态为 302 的 AccessDenied 页面 -> 这不是我想要的。
而不是重定向 AccessDenied 页面。我希望 ASP.NET Core 抛出我的自定义 ForbiddenException 异常,这样我就可以像处理未处理的异常一样处理未经授权的访问。
这是我的身份验证配置:
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme; // Cookies
options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme; // Cookies
options.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme; // Cookies
})
.AddCookie(options => {
options.LoginPath = "/Auth/Login/";
options.LogoutPath = "/Auth/Logout/";
// I want disable this and throw ForbiddenException instead.
options.AccessDeniedPath = "/Auth/AccessDenied/";
});
有人帮忙吗?谢谢!
【问题讨论】:
标签: c# asp.net-core asp.net-core-2.0 authorize-attribute asp.net-authorization