How to check for correct url
<p>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 <code>Global.asax</code> on the <code>Application_BeginRequest</code> method, we check for the urls such as if someone enters <code>http://mywebtest/badurl</code> 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?</p>

<pre><code>If a page with .aspx is requested that does not exist, 
to redirect it to the custom 404  page?
</code></pre>

<p>I was trying something like (but its just a guess) and it did not work..</p>

<pre><code>if ((string)System.IO.Path.GetExtension(Request.Path) == string.Empty)
                    {
                        HttpContext.Current.RewritePath("~/custom404.aspx");
                    }
</code></pre>

<p>Thank you</p>
