January 9, 2013

Handle Response.Statuscode=404

-------------------
DEFINITION :
-------------------

The 404 or Not Found error message is a HTTP Standard Response Code indicating that client was able to communicate with the server but the server could not find what was requested.


-----------------
SOLUTION :
-----------------

You can handle Error Code 404 in following ways.

There are three places in ASP.NET to define what happens to these unhandled errors.

  • In web.config file, Custom Error section. (Use it within <system.web>)
<customErrors mode="On" defaultRedirect="Error.htm">
       <error statusCode="500" redirect="Error500.htm">
       <error statusCode="401" redirect="Error401.htm" />
       <error statusCode="404" redirect="Error404.htm" />
      <error statusCode="403" redirect="Error403.htm" />
</customErrors>
  • In global.asax file, Application_Error method.
  • In code-behind file, Page_Error method.
The actual order to error handling is as follow.
  • In code-behind file
  • In global.asax file
  • In web.config file

No comments:

Post a Comment