gpt4 book ai didi

c# - 错误页面上的 ASP.net 捕获错误

转载 作者:太空宇宙 更新时间:2023-11-03 23:12:41 25 4
gpt4 key购买 nike

我已经设置了可以正常工作的自定义错误页面:

<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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com