我的web.config:
<customErrors mode="Off" redirectMode="ResponseRewrite" defaultRedirect="~/Pages/Error/DefaultError.aspx">
<error statusCode="404" redirect="~/Pages/Error/Page404.aspx" />
<error statusCode="500" redirect="~/Pages/Error/DefaultError.aspx" />
</customErrors>
<httpErrors existingResponse="Replace" defaultResponseMode="ExecuteURL" errorMode="Custom"> //also used other options for existingResponse
<remove statusCode="403"/>
<error statusCode="403" path="~/Pages/Error/PI403.aspx" responseMode="ExecuteURL"/>
</httpErrors>下面是我在global.asax.cs文件中的Application_error方法:
Server.ClearError(); //clear the error so we can continue onwards
var errorPage = "~/Pages/Error/DefaultError.aspx";
var httpException = ex as HttpException;
if (httpException != null && httpException.GetHttpCode() == (int)HttpStatusCode.NotFound)
{
errorPage = "~/Pages/Error/Page404.aspx";
}
Response.Redirect(errorPage);我在项目中有日志文件,但这个文件只使用日志。如果我使用myURL/Logs浏览器链接,我会得到IIS 403.14错误页。如果我编写myURL/asdeds,我会得到我的自定义错误页面(在我的项目中没有类似的东西)。因为403异常不会触发Application_Error。我想要显示所有异常的自定义错误页面。当我将myURL/Logs写入URL部分时,我应该会看到我的自定义错误页面。
我还在Application_BeginRequest中设置了TrySkipIisCustomError属性
HttpContext.Current.Response.TrySkipIisCustomErrors = true;
发布于 2020-11-18 21:57:12
首先,您必须转到IIS



上的应用程序重复步骤1、2和3

的错误页


不要忘记,此操作是在服务器上执行的。现在,如果一个请求被发送到服务器(smp:https :// yoursite.com/scripts)并且你得到了错误302,你想要的页面就会被打开。
https://stackoverflow.com/questions/58028102
复制相似问题