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?

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.