我有以下代码在Global.asax.cs中进行404重定向
protected void Application_Error(object sender, EventArgs e)
{
Exception ex = Server.GetLastError();
if (ex.InnerException != null)
ex = ex.InnerException;
if ((ex is HttpException && ((HttpException)ex).GetHttpCode()==404 ))
{
Response.Redirect("~/Custom404Page.aspx");
}
}
它在visual studio中工作正常,并获得用户友好的Custom404Page。
但是当我在IIS 7.0中部署它时,它根本不起作用。显示以下消息
在web.config中
<customErrors mode="RemoteOnly" defaultRedirect="/Error.aspx" />
由于某种原因,我们被要求不在statusCode="404"
的web.config中添加任何条目。所以我们在global.asax.cs
为什么它在IIS中不起作用。
更新: domain/blahblah
未显示Custom404Page。但domain.blahblah.aspx
显示Custom404Page.aspx。如何使用SEO友好网址domain/blahblah