0

I have made custom error page on asp.net and it works good only for .aspx pages For .htm pages it redirects to a blank page. Help please, a have no strength any more((

This is my code in Global.asax -

protected void Application_Error(object sender, EventArgs e)
        {
            Exception ex = Server.GetLastError();
            if (ex is HttpException)
            {
                if (((HttpException)(ex)).GetHttpCode() == 404)

                    Server.Transfer("~/error404.htm");
            }
            Exception objErr = Server.GetLastError().GetBaseException();
            string err = "Error in: " + Request.Url.ToString() +
                              ". Error Message:" + objErr.Message.ToString();
            Server.Transfer("~/ErrorPage.aspx");
        }

and in Web.config -

<system.web>
<customErrors mode="On" defaultRedirect="~/ErrorPage.aspx">
      <error statusCode="404" redirect="~/error404.htm"/>
    </customErrors>
</system.web>

and -

<system.webServer>
     <modules runAllManagedModulesForAllRequests="true"/>
    <httpErrors errorMode="Custom">
      <remove statusCode="404" subStatusCode="-1"/>
      <error statusCode="404" path="~/error404.htm" responseMode="ExecuteURL"/>
    </httpErrors>
</system.webServer>

HELP!!(( Thanks!

John Lenin
  • 51
  • 2
  • 4
  • Looks a lot like this question: http://stackoverflow.com/questions/6648007/iis7-custom-404-not-showing, does the configuration they suggest there help? – Evan Dec 16 '11 at 16:55

2 Answers2

0

Try to redirect with the following syntax:

Server.Transfer(@".\error404.htm");

or

Response.Redirect(@".\error404.htm");
Hovo
  • 190
  • 1
  • 11
0

Well, the above configuration applies to requests processed by the asp.net pipeline. Unless you have .html files mapped to the aspnet_isapi.dll, none of this configuration is relevant.

You can configure the server to redirect 404s to your custom page, but that is at the IIS level, not the asp.net level.

Mark Sherretta
  • 10,160
  • 4
  • 37
  • 42