我接着對如何設置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頁面。 (「該頁無法找到」)
我缺少什麼?