【问题标题】:On Exception, application stopped responding from custom error page出现异常时,应用程序停止从自定义错误页面响应
【发布时间】:2017-02-24 12:49:46
【问题描述】:

我有一个部署在 IIS 7 上的 .NET 应用程序。该应用程序应该可以从 IE7 访问。如果发生特殊类型的异常,我会将页面重定向到带有后退按钮的普通 .htm 页面,onclick 应该将用户带回上一页。我在 global.asax 文件中做这个异常处理。下面是我的 Global.asax 代码:

protected void Application_Error(Object sender, EventArgs e)
{
 if (GlobalHelper.IsMaxRequestExceededException(this.Server.GetLastError()))
  {
    this.Server.ClearError();
    this.Server.Transfer("Error.htm");
  }
}

这是我的.htm 页面:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title></title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="ProgId" content="VisualStudio.HTML">
<meta name="Originator" content="Microsoft Visual Studio .NET 7.1">
</head>
<body>
<TABLE cellSpacing="1" cellPadding="1" width="100%" border="0" height="100%">
    <TR>
        <TD height=256 align=center><font color ="red">Exception Occurred !!<br>
        Kindly contact your system administrator</font></TD>
    </TR>
    <TR>
        <TD height=41 align =center><button onclick="history.go(-1);" type=button>Back</button></TD>
    </TR>
    <TR>
        <TD></TD>
        <TD></TD>
        <TD></TD>
    </TR>
</TABLE>
</body>
</html>

现在在上面,.htm 后退按钮单击&lt;TD height=41 align =center&gt;&lt;button onclick="history.go(-1);" type=button&gt;Back&lt;/button&gt;&lt;/TD&gt;,我收到“此页面无法显示”消息。

这里有什么问题?

【问题讨论】:

    标签: javascript html .net internet-explorer iis


    【解决方案1】:

    问题不在于异常本身,而在于您发送错误页面的方式。
    您需要更改:

    this.Server.Transfer("Error.htm");
    

    到这里:

    this.Response.Redirect("Error.htm", true);
    

    两种方式的区别在于,当您使用 Server.Transfer 时,浏览器不知道他收到的页面不是这里解释的请求的页面:

    Correct way to do a Response.Redirect from one page to another on the same site

    【讨论】:

    • 谢谢。实际上,this.Server.Transfer("Error.htm"); 运行良好,我可以联系到Error.htm。问题是当我试图通过&lt;TD height=41 align =center&gt;&lt;button onclick="history.go(-1);" type=button&gt;Back&lt;/button&gt;&lt;/TD&gt; 返回上一页时。正在显示,页面无法显示。有什么想法吗?
    • Server.Transfer 用于重定向页面,但它的工作方式使浏览器失去了对前一页的跟踪。是否有理由只使用 Server.Transfer?如果没有,请尝试使用 Response.Redirect。
    • 不,没有具体原因。一定会尝试的。谢谢
    • 已更新为this.Response.Redirect("Error.htm", true);,但问题相同。仍然收到页面​​无法显示消息
    • 尝试使用“windows.history.go(-1);”如此处所示:stackoverflow.com/questions/16253035/… 看起来像是浏览器兼容性问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-08
    • 1970-01-01
    • 2013-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多