3

Just trying to detect if it's 404 error in application. For example user tries in url and IIS shows 404 not found.

I want to detect 404 error. Redirect to custom 404 page and pass message like "cound't find" dynamically from the codebehind.

Has anyone ever done that?

Mert
  • 99
  • 12

1 Answers1

2

Handle 404 using web.config custom errors, this is the correct way to handle this type of errors, and in NotFound.aspx page you can log the error.

<configuration>
  <system.web>
    <customErrors mode="On" >
      <error statusCode="404" redirect="NotFound.aspx"/>
    </customErrors>
  </system.web>
</configuration

Noway to handle all 404 exceptions from code behind, because the generic handler of exception could be implemented in global.asax - (Application_Error method), this handler able to catch any error occurred on asp.net application layer and cannot handle 404 request because you are request something outside of asp.net.

Mohammad Ghanem
  • 688
  • 6
  • 20