문제

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

enter image description here

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

올바른 솔루션이 없습니다

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top