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.
If you do want to allow it, try setting
relaxedUrlToFileSystemMapping = truein your web.config.MSDN Link and here it is in context.
Alternatively, make this config change and then choose to return the relevant error message, or redirect them or whatever you want to do.
EDIT: If you just want to allow the colon in the request string for a single method you can always decorate that Action Method with
[ValidateInput(false)]as explained in more detail in this answer of mine. This means that you don't need to downgrade your request validation in the web.config.