我接着对如何设置404忠告:获取所有404对IIS6
http://www.andornot.com/about/developerblog/archive/2009_10_01_archive.aspx
及相关:
Best way to implement a 404 in ASP.NET
从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);
}
}
而且从Web.config文件:
<customErrors mode="On"/>
它在测试(VS2010)时在本地很精美,但在生产(ISS6)中它只能用于aspx页面。 http://mysite.se/foo.js让我看看ISS 404页面。 (“该页无法找到”)
我缺少什么?