在异常时,应用程序从自定义错误页面停止响应

时间:2017-02-24 12:49:47

标签: javascript html .net internet-explorer iis

我有一个部署在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后退按钮点击<TD height=41 align =center><button onclick="history.go(-1);" type=button>Back</button></TD>,我得到一个&#34;此页面无法显示&#34;消息。

这里有什么问题?

1 个答案:

答案 0 :(得分:0)

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

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

相关问题