ASP.NET MVC:如何处理400错误的请求错误的URL时结束与% [英] ASP.NET MVC: How to handle 400 bad request error when url end with %

查看:791
本文介绍了ASP.NET MVC:如何处理400错误的请求错误的URL时结束与%的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图处理所有HTTP错误我的自定义错误页,但我发现,当有在网址的结尾是一个%,我无法使用配置设置或code来处理它,
例如:的http://本地主机/ ABC%
的响应是:
错误的请求 - 无效的网址
HTTP错误400.请求URL是无效的。

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 example: http://localhost/abc% the response is: Bad Request - Invalid URL HTTP Error 400. The request URL is invalid.

所以,我们可以使用配置设置或C#code来处理这个错误的请求?

So, can we use config setting or c# code to handle this error request?

推荐答案

请参阅IIS配置中自定义错误页这4部分组成的系列:<一href=\"http://www.dotnetscraps.com/dotnetscraps/post/Did-you-know-Enable-Custom-Error-in-IIS-7-75.aspx\" rel=\"nofollow\">http://www.dotnetscraps.com/dotnetscraps/post/Did-you-know-Enable-Custom-Error-in-IIS-7-75.aspx.

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.

我个人preFER使用 Application_Error事件记录错误和重定向用户自定义错误页。请注意,您需要使用综合管线在IIS中捕获所有的错误,否则IIS将显示它自己的错误页面,不是由ASP.NET提供的资源。

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.

编辑:
对不起,错误的答案。我目前的XP的机器,显示404%的迹象所以无法核实以上。搜索互联网,我发现它只是无法为400状态code 显示自定义错误页。见<一href=\"http://serverfault.com/questions/257680/properly-handle-iis-request-with-percent-sign-in-url\">this从服务器故障问题,以了解更多信息。

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.

这篇关于ASP.NET MVC:如何处理400错误的请求错误的URL时结束与%的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆