ASP.NET Application hosted on IIS7 that is ignoring custom errors and falls back to IIS errors

前端 未结 3 1471
死守一世寂寞
死守一世寂寞 2020-12-06 05:44

I have a C# web forms ASP.NET 4.0 web application that uses Routing for URLs for some reason custom errors defined in the system.web section of my web.config is entirely ign

相关标签:
3条回答
  • 2020-12-06 06:24

    Instead of using:

    Response.TrySkipIisCustomErrors = true;
    

    Use this in Web.config:

    <httpErrors errorMode="Custom" existingResponse="Replace">
    
    0 讨论(0)
  • 2020-12-06 06:33

    You can pass through IIS7 default error messages in two ways One is to set response.TrySkipIisCustomErrors = true

    response.TrySkipIisCustomErrors = true;
    response.Status = response.Status;
    

    For some reason, TrySkipIisCustomErrors is not honoured if you don't set response.Status.

    The other is to set existingResponse to "PassThrough" in web.config

    <configuration>
      <system.webServer>
        <httpErrors existingResponse="PassThrough" />
      </system.webServer>
    </configuration>
    

    But this will ignore all set IIS custom error pages.

    0 讨论(0)
  • 2020-12-06 06:38

    To disable the IIS error messages you have to set

      Response.TrySkipIisCustomErrors = true;
    

    in your error page. After that, your Error messages should show without problem.

    0 讨论(0)
提交回复
热议问题