处理asp.net中的Web API错误的请求 [英] Handling bad request in asp.net web api
问题描述
我有一个API URL像下面我mvc4应用
I have a api url like below in my mvc4 app
http://localhost:15839/api/mydata/getdata/3365895543/PROBLEMDATA/myotherparam
现在的客户在消费上面的URL发送 HTT prequest
。在回应 API
正在发回一个响应
。但在的网址用户的PROBLEMDATA
发送那些给我坏请求坏字符 - 无效的网址
。我无法将客户端源强制EN code数据。我需要处理它在我的web API,并给回我的客户一个字符串不成功的
。我所看到的这的WebAPI周期疑惑在这一点,我应该处理这个问题。可能是在HTTP消息处理程序,而是如何?
Now client is consuming the above url to send httprequest
. In response api
is sending back a response
. but in PROBLEMDATA
of the url user is sending bad characters that are giving me Bad Request - Invalid URL
. I can't force my client source to encode data. i need to handle it in my web api and give back my client a string "Unsucessful"
. I have seen this webapi cycle wondering at which point I should handle this. probably at http message handler but How?
我可能需要按照这个一>。但寄存器(HttpConfiguration配置)
也不会被打到
I may need to follow this. but Register(HttpConfiguration config)
also doesn't get hit
推荐答案
我相信你可以通过重写的的Application_Error 方法。从那里,我想你可以生产的不成功的反应或转嫁给在控制器级别来处理请求。
I believe you can capture this globally by overriding the application_error method. From there I suppose you could produce the "unsucessful" response or pass the request along to be handled at the controller level.
<一个href=\"http://stackoverflow.com/questions/7511239/asp-net-mvc-how-to-handle-400-bad-request-error-when-url-end-with\">Take一看这个问题以及。
这篇关于处理asp.net中的Web API错误的请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!