GVillani82 GVillani82 - 1 year ago 114
ASP.NET (C#) Question

Trouble passing datetime parameter to web service, in GET

I created a web service using ASP .NET Web API. The method is:

public IHttpActionResult getService(String applicantUser, DateTime? lastUpdate = null){
// some stuff here


If I call the WS in this way:


all works good, and I obtain a correct json file. But if I try to add the time:


I obtain the error
404 - Bad Request

Answer Source

The problem is the colun (:) character in the URL which is not allowed. You can either put the parameter in the query string:


Or disable the validation to check for potentially dangerous request paths by merging this to your web.config:

    <httpRuntime requestPathInvalidCharacters="" requestValidationMode="2.0" />
    <pages validateRequest="false" />
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download