Is this a good way to catch all 404s in .NET without playing with IIS configuration? The situation is that its not always possible to play with the web.config or have access to IIS, that being said I had to come up with a way to catch all 404s in a .NET application, for aspx page extensions its fairly easily and the web is full of ideas... but for non aspx extensions I did the following, looking for advice, is this a good way? are their scenarios where it might fail? does it measure well in performance? thanks for advice

After checking my web.sitemap links and make my rewrites, the "else" block contains the following

string s = context.Server.MapPath(context.Request.AppRelativeCurrentExecutionFilePath);
if (!System.IO.File.Exists(s)){
    throw new HttpException(404, "Page not found");
}


and of course, the rest is handled by the application error handler
notice that all css, js, jpegs and other file types go through this check

edit: two problems seem to be persistent with regular error catch, html and friendly urls, they never seem to fire 404s (guessing there other file types, depends on isapi filters)
404 is an error and normally should be captured with a relative event. Since you have a custom module you can do the following in the module:

public void Init(HttpApplication context)
{
    // your code
    context.Error +=new EventHandler(OnError);
}

private void OnError(object sender, EventArgs e)
{
    int ec = ((HttpException)HttpContext.Current.Error).GetHttpCode();
    if (ec == 404)
    {
        // do whatever you want
    }
}


If you follow this path you will have the advantage to control all error codes your way and avoid early 404 drops in case you change your rewriting policy or logic.