I am creating a webAPI, and when i include a colon(:) in the request string,
i get this error:
A potentially dangerous Request.Path value was detected from the client (:).
[HttpException (0x80004005): A potentially dangerous Request.Path value was detected from the client (:).] System.Web.HttpRequest.ValidateInputIfRequiredByConfig() +9673044 System.Web.PipelineStepManager.ValidateHelper(HttpContext context) +53
I don't plan to include special characters in the actual requests for the api, but if some no-good user inputs special characters in the requests it would cause an error.
Question: How do i handle this error on the API side? Is there any way? Or should i just give the developers a note about this issue?
Note: I don't have controls over the future clients whose going to access the API. I am using Visual Studio 2012 for Web; .Net version 4.0; ASP.Net WebApi; and C#; I do think the code is unnecessary for my case, the Api works except for those certain special characters. But if you think otherwise, please do tell me what else you need to know.
Another Note: I'm not trying to find ways to allow it in a url, i'm just looking for ways to handle the error specifically.
You could implement an ExceptionFilterAttribute. For example:
This attribute can be used on an action method, a controller or globally. But don't forget to register this filter on startup. More details can be found here: Exception Handling in ASP.NET Web API.