Reputation: 11498
I've followed advice on how to setup 404s by:
http://www.andornot.com/about/developerblog/archive/2009_10_01_archive.aspx
and related:
Best way to implement a 404 in ASP.NET
From Global.asax:
protected void Application_Error(Object sender, EventArgs e)
{
Exception exception = Server.GetLastError();
if (exception is HttpUnhandledException)
{
if (exception.InnerException == null)
{
Server.Transfer(string.Format("~/Error.aspx", false));
return;
}
exception = exception.InnerException;
}
if (exception is HttpException)
{
if (((HttpException)exception).GetHttpCode() == 404)
{
Server.ClearError();
Server.Transfer("~/404.aspx", false);
return;
}
}
if (Context != null && Context.IsCustomErrorEnabled)
{
Server.Transfer(string.Format("~/Error.aspx"), false);
}
}
And from Web.config:
<customErrors mode="On"/>
It all works beautifully locally while testing (VS2010) but in production (ISS6) it only works for aspx pages. http://mysite.se/foo.js get me the ISS 404 page. ("The page cannot be found")
What am I missing?
Upvotes: 1
Views: 1648
Reputation: 26956
If you don't want to set up wildcard mappings, or have ASP.NET handle all your static files (and generally performance might well say you don't), you need to configure IIS 6 to send 404's to an aspx page that handles the errors.
Point 4 is the key - it needs to point to a file that exists, otherwise IIS will revert to the default.
Upvotes: 4
Reputation: 8421
The 404 handler specified in the Web.Config
only deals with files handled by the ASP.NET runtime, all others including JavaScript files will be handled by the 404 page specified in your IIS settings. This is the reason why you are seeing the IIS generated error message for http://mysite.se/foo.js
instead of the one specified in the custom errors section of the Web.Config
.
You can, however, map these file types to the aspnet_isapi.dll to have them handled by your custom error pages.
See here for more information.
Upvotes: 2