1

I have a api url like below in my mvc4 app

http://localhost:15839/api/mydata/getdata/3365895543/PROBLEMDATA/myotherparam

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?

I may need to follow this. but Register(HttpConfiguration config) also doesn't get hit

Tassadaque
  • 8,129
  • 13
  • 57
  • 89
  • did you want the request to reach the *intended* api controller or just handle the error better? – wal Jul 29 '13 at 06:59
  • If request can reach the controller that is will be great Other wise i wan to send json response "unscussful" back to client – Tassadaque Jul 29 '13 at 07:20
  • That last link you provided (`DelegatingHandler`) doesnt appear to help anyway because a 400 bad request is validated *before* it hits this. It may be impossible to do what you want to do in web api - its probably best to ask this on the dedicated web api forum: http://forums.asp.net/1246.aspx/1?ASP+NET+Web+API – wal Jul 29 '13 at 12:35

1 Answers1

0

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.

Take a look at this question as well.

Community
  • 1
  • 1
James Santiago
  • 2,883
  • 4
  • 22
  • 29
  • how would you 'pass the request along to be handled at the controller level' ? – wal Jul 29 '13 at 07:15
  • @wal either by using Response.Redirect or by declaring the appropriate controller as an IController and using the execute method. By doing some regex branching off the RawUrl you could guess where you need to send the response or send the request to an error controller as a lost resort. – James Santiago Jul 29 '13 at 07:21
  • thats not ideal as you now need to do a quasi-implementation of the api routing to get to the right controller – wal Jul 29 '13 at 07:31
  • 2
    [According to this](http://serverfault.com/questions/257680/properly-handle-iis-request-with-percent-sign-in-url) it looks like the request is unlikely to make it to the application level at all. – James Santiago Jul 29 '13 at 07:39
  • Request is not reaching the controller. I think i should follow http://www.asp.net/web-api/overview/working-with-http/http-message-handlers this but it is also not working – Tassadaque Jul 29 '13 at 08:12