I am working on a current web app and we would like to determine if the page being requested is correct or not, we do this in a Global.asax on the Application_BeginRequest method, we check for the urls such as if someone enters http://mywebtest/badurl then we send them to a custom 404 page, but we are having trouble making it work when it has a .aspx extension, there are pages that are good with aspx extensions but others that do not exist should be fowarded to the custom 404. How can we do this?
If a page with .aspx is requested that does not exist,
to redirect it to the custom 404 page?
I was trying something like (but its just a guess) and it did not work..
if ((string)System.IO.Path.GetExtension(Request.Path) == string.Empty)
{
HttpContext.Current.RewritePath("~/custom404.aspx");
}
Thank you
Check out these links:
File.Exists method
Check if URL exists
Display a Custom Error Page