Ian*_*ton 6 asp.net-web-api asp.net-core-2.0
我已从 Web 请求返回Forbid(),浏览器声称收到 404 而不是 403。
我已经向 cookie 身份验证添加了一个处理程序,如下所示......
o.Events.OnRedirectToAccessDenied += ctx =>
{
ctx.Response.StatusCode = (int)HttpStatusCode.Forbidden;
return Task.FromResult(0);
};
Run Code Online (Sandbox Code Playgroud)
但这似乎没有被调用。
那么,为什么应该返回 403 的方法却返回 404 呢?
我遇到过同样的问题。这些是我修复它的步骤:
app.UseExceptionHandler("/Home/Error")from Startup. 就我而言,404发生这种情况是因为异常处理被破坏。在我添加正确的身份验证选项后Startup(在我的例子中,我使用了自定义身份验证处理程序),我得到了正确的响应代码:
services.AddAuthentication(LicenseKeyAuthenticationOptions.Scheme)
.AddScheme<LicenseKeyAuthenticationOptions, LicenseKeyAuthenticationHandler>(LicenseKeyAuthenticationOptions.Scheme, null);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1248 次 |
| 最近记录: |