How to tell if Application_Error is caused by HTTP error 404?

  • Thread starter Thread starter Edward
  • Start date Start date
E

Edward

I have a need to detect if an error is caused by HTTP error 404 in
Application_Error (in global.asax). I read MSDN docs but did not get an
answer.

Is there a reliable workaround to detect this status?
 
Edward said:
I have a need to detect if an error is caused by HTTP error 404 in
Application_Error (in global.asax). I read MSDN docs but did not get an
answer.

Is there a reliable workaround to detect this status?

404 Not Found is caught by IIS, not your webapplication. Your webapplication
will never get this error. What you could do is configure IIS to redirect to
a certain error page which your application could use to detect the 404.
 
Bresco said:
404 Not Found is caught by IIS, not your webapplication. Your webapplication
will never get this error. What you could do is configure IIS to redirect to
a certain error page which your application could use to detect the 404.
I can trap 404 error by <customErrors> in web.config. I have tested this
in IIS and it's working.

I find a way to check 404 in Application_Error:

File.Exists(this.Request.PhysicalPath);

But I am not sure if it is reliable.
 
Back
Top