2

I have a .NET application which is deployed on IIS 7. The application is supposed to be accessed from IE7. If a special kind of exception occurs, I am redirecting the page to a plain .htm page with a back button which onclick should take the user back to previous page. I am doing this exception handling inside the global.asax file. Below is my Global.asax code:

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

Here is my .htm page:

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

Now in the above, the .htm back button click <TD height=41 align =center><button onclick="history.go(-1);" type=button>Back</button></TD>, I am getting a "This page can not be displayed" message.

What is wrong here?

Ashish Bahl
  • 1,482
  • 1
  • 18
  • 27
Lara
  • 2,821
  • 7
  • 39
  • 72

1 Answers1

0

The problem is not the Exception itself, but the way you are sending the error page.
You need to change the:

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

To this:

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

The difference between both ways is that when you use the Server.Transfer the browser didn't know that he page received is not the page requested as explained here:

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

Community
  • 1
  • 1
Balbinator
  • 220
  • 2
  • 9
  • Thanks. Actually, `this.Server.Transfer("Error.htm");` is working good and i am able to reach `Error.htm`. Issue is when i am trying to go back to immediate previous page by ``. This is displaying, page can not be displayed. Any thoughts ? – Lara Feb 24 '17 at 13:53
  • The Server.Transfer works on redirecting the page, but the way it does it makes the browser lose the track of what was the previous page. Is there a reason to use only Server.Transfer? If not, try it with the Response.Redirect. – Balbinator Feb 24 '17 at 14:13
  • No there is no specific reason for the same. Definitely will try. Thanks – Lara Feb 24 '17 at 14:27
  • Updated with `this.Response.Redirect("Error.htm", true);` but issue is same. Still getting Page can not be displayed messsage – Lara Feb 24 '17 at 15:18
  • Try with "windows.history.go(-1);' as seen here: http://stackoverflow.com/questions/16253035/onclick-javascripthistory-go-1-not-working-in-chrome It looks like a browser compatibility issue. – Balbinator Feb 24 '17 at 16:58