0

When I try to hit invalid endpoint which contains space. Example:

http://localhost/myapiproject/api/v1/property/1234/package /5678

Server responds with complete stack trace. Example:

Server Error in '/myapiproject' Application.

The resource cannot be found. 
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly. 

Requested URL: http://localhost/myapiproject/api/v1/property/1234/package /5678
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.1586.0 

I have tried Global Error handling methods to resolve the issue but no luck. I tried Using ExceptionHandler

I want to send empty response with 404 status code. How can I do that?

I tried to capture exception in Application_Error method in Global.asax file. But this method is not being executed. I already have defined default controller which takes care of non existing urls with status code 404. It only fails when url contains space.

Community
  • 1
  • 1
Dharmesh
  • 943
  • 4
  • 15
  • 26
  • This will give you a good solution. http://stackoverflow.com/questions/27819570/asp-net-mvc-how-to-handle-404-error-from-application-error-without-rewriting-the – Dan Hunex Dec 29 '16 at 19:20
  • @DanHunex This solution is trying to solve different problem it seems. Also in my case Application_Error method is not getting executed. – Dharmesh Dec 29 '16 at 20:07
  • 1
    Have a look at [this answer](http://stackoverflow.com/a/5507125/2030565) – Jasen Dec 29 '16 at 20:22
  • Possible duplicate of [How to handle WebApi error 404](http://stackoverflow.com/questions/31782020/how-to-handle-webapi-error-404) – Jeff Siver Dec 29 '16 at 21:44
  • I solved problem by adding `` in web.config file. You can find more info [here](http://stackoverflow.com/questions/13406265/webapi-route-404s-when-there-is-a-trailing-space-in-the-url). Solution is same though it is solving different problem. Also I don't know if there is any security risk in setting this property to true. – Dharmesh Jan 05 '17 at 14:32

0 Answers0