ASP.Net 404 Redirect for friendly url not working

你说的曾经没有我的故事 提交于 2019-12-24 12:00:27

问题


I have the below code to do 404 redirect in Global.asax.cs

   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");
        }
    }

It works fine in visual studio and getting user friendly Custom404Page.

But when I deploy the same in IIS 7.0, it is not at all working. Shows the below message

In web.config

<customErrors mode="RemoteOnly" defaultRedirect="/Error.aspx" />

Due to some reason we are asked not to put any entries in web.config for statusCode="404". So we did in global.asax.cs

Why it is not working in IIS.

UPDATE: domain/blahblah is not showing Custom404Page. But domain.blahblah.aspx, shows Custom404Page.aspx. How to make it work with SEO friendly url domain/blahblah

来源:https://stackoverflow.com/questions/22144777/asp-net-404-redirect-for-friendly-url-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!