So I have one endpoint on my ASP.NET Web API project that needs to accept special characters (such as %
, <
, >
) to validate the uniqueness of a name within the system. So for the following route:
[Route("~/api/case/{name}/infosys/{system}")]
... {name}
may contain a special character. For this endpoint only is there a way that I can tell Web API to allow special characters and not give this error:
HttpException (0x80004005): A potentially dangerous Request.Path value was detected from the client (%).
Note: This is a Web API project so the [ValidateInput(false)]
and [AllowHtmlAttribute]
decorators are not available. Also, I don't want to loosen this restriction on any other endpoint by modifying my Web.config:
No
<httpRuntime requestValidationMode="2.0" />
...
No
<pages validateRequest="false">
...
No
<httpRuntime requestPathInvalidCharacters="<,>,%,&,:,\,?" />
I tested this piece of code and it works:
httpRuntime targetFramework="4.5.1" requestPathInvalidCharacters="<,>,*,%,&,\,?"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With