Catching / Redirecting 404's (ASP.NET)
Posted
by
maxp
on Stack Overflow
See other posts from Stack Overflow
or by maxp
Published on 2010-12-23T14:29:56Z
Indexed on
2010/12/23
14:54 UTC
Read the original article
Hit count: 127
Ive noticed that when I request a page in ASP.NET (webforms) that does not exist, the 'StaticFile' handler deals with the error notification.
Id like to be a bit more helpful in these situations.
What is the correct way for me to intercept this 404, and as a result, run some code to redirect the user?
Two ways Ive thought of doing which I currently don't really like are:
1 - Create a module that basically does a if (!file.exists($url){redirect to $correctedurl})
2 - Modify the error.aspx.cs(or the default error page) to do something similar (yuck!)
© Stack Overflow or respective owner