I created a web service using ASP .NET Web API. The method is:
[HttpGet]
[Route("service/{applicantUser}/{lastUpdate:datetime?}")]
public IHttpActionResult getService(String applicantUser, DateTime? lastUpdate = null){
// some stuff here
}
If I call the WS in this way:
http://myserver/api/service/myusername/2008-12-10
all works good, and I obtain a correct json file. But if I try to add the time:
http://myserver/api/service/myusername/2008-12-10T12:30:00
I obtain the error 404 - Bad Request
The problem is with the colon (:
) character in the URL which is not allowed. You can either put the parameter in the query string:
http://myserver/api/service/myusername/?lastUpdate=2008-12-10T12:30:00
Or disable the validation to check for potentially dangerous request paths by merging this to your web.config
:
<system.web>
<httpRuntime requestPathInvalidCharacters="" requestValidationMode="2.0" />
<pages validateRequest="false" />
</system.web>
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments