ASP.NET MVC: How to handle 400 bad request error when url end with %

前端 未结 2 1483
我寻月下人不归
我寻月下人不归 2021-01-19 18:15

I am trying to handle all HTTP errors to my custom error pages, but I find that when there is a % at the end of url, i cannot use config setting or code to handle it, for e

相关标签:
2条回答
  • 2021-01-19 18:36

    See this 4 part series for configuring custom error pages within IIS: http://www.dotnetscraps.com/dotnetscraps/post/Did-you-know-Enable-Custom-Error-in-IIS-7-75.aspx.

    I personally prefer to use Application_Error event to log the errors and redirect user to custom error pages. Note that you need to use integrated pipe-line in IIS to catch all errors otherwise IIS will show its own error page for resources that are not served by ASP.NET.

    EDIT: Sorry for the wrong answer. I have XP machine currently that shows 404 for % sign so couldn't verify above. Searching over internet, I found that it's simply not possible to display custom error page for 400 status code. See this question from server fault for more information.

    0 讨论(0)
  • 2021-01-19 18:40

    Who said not possible?

    Response.TrySkipIisCustomErrors = true;
    

    OR

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

    original post

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