ASP.Net 404重定向友好网址无法正常工作

时间:2014-03-03 10:52:17

标签: c# asp.net iis redirect http-status-code-404

我有以下代码在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中部署它时,它根本不起作用。显示以下消息

enter image description here

在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

0 个答案:

没有答案