![](/img/trans.png)
[英]Intercept API Response(Error code: 403) using a ASP.NET Core Middleware
[英]asp.net 403 response code not firing custom error
我在web.config中设置了一个自定义错误,如下所示:
<customErrors mode="On" defaultRedirect="Error.aspx">
<error statusCode="403" redirect="AuthenticationRequired.aspx" />
<error statusCode="404" redirect="NotFound.aspx" />
</customErrors>
我在page_load事件上有一些代码可以检查用户权限...如果失败,则创建以下响应...但这不是由自定义错误捕获的,任何人有任何想法吗?
Response.StatusCode = 403;
Response.Status = "403 Forbidden";
Response.End();
您应该尝试使用以下代码
Response.TrySkipIisCustomErrors = true;
如果您使用的是IIS 7。
改用Web.Server httpErrors
:
<system.webServer>
<httpErrors errorMode="Custom" >
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" path="/NotFound.aspx" responseMode="Redirect" />
</httpErrors>
</system.webServer>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.