我已经设置了可以正常工作的自定义错误页面:
<customErrors mode="On" redirectMode="ResponseRewrite">
<error statusCode="500" redirect="~/Pages/ErrorPages/500.aspx" />
</customErrors>
在 500.aspx
上:
Response.ClearContent();
Response.StatusCode = 500;
Exception = Server.GetLastError();
Code.Errors.Error.RecordNewError(ErrorType.InternalException, Exception, Code.Common.GetUserIPAddress().ToString(), HttpContext.Current);
Server.ClearError();
问题是,如果错误页面本身抛出错误,我们会得到一个难看的错误:
Runtime Error
Description: An exception occurred while processing your request. Additionally, another exception occurred while executing the custom error page for the first exception. The request has been terminated.
如果错误页面本身抛出错误,我如何回退到更基本的自定义错误页面?
最佳答案
刚刚想通了!在错误页面本身上使用 Page_Error
方法:
private void Page_Error(object sender, EventArgs e)
{
Response.ClearContent();
Response.StatusCode = 500;
Exception = Server.GetLastError();
HttpContext.Current.Response.Write("Error");
HttpContext.Current.Response.End();
}
关于c# - 错误页面上的 ASP.net 捕获错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38505968/