Work with date in web api

I created a WEB API using a MySQL . The table contains data on the serial numbers of the counter, which correspond to the signal strength values ​​and the date of the time at which the signal strength arrives. So far, I manage to get the data by sending the serial number of the counter.

Now I will also send him a date time parameter. But this does not work for me. Here is what I did.

 public HttpResponseMessage GetByMsn(string msn, DateTime dt) { try { return Request.CreateResponse(HttpStatusCode.Found, medEntitites.tj_xhqd.Where(m=> m.msn == msn).Where(a=> a.date_time < dt )); } catch (Exception ex) { return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex); } } 

WebApiConfig file includes

 config.Routes.MapHttpRoute( name: "GetByMsn", routeTemplate: "api/{controller}/{action}/{msn}/{dt}", defaults: null, constraints: new { msn = @"^[0-9]+$" , dt = @"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$" } ); 

After that, I pass the URL as http://localhost:14909/api/meters/GetByMsn/000029000033/2017-10-06T07:52:27

The error I get is A potentially dangerous Request.Path value was detected from the client (:).

For this, I also looked for solutions, but could not find the right one. I also replaced : with a date, but still it does not work for me

Update 1

When transferring only the dates 2017-10-06 it works for me, but when I add it over time, it does not work

For a quick check, I checked this question , but still can't solve the problem.

I need to miss something I don't know

Any help would be greatly appreciated.

0
rest mysql visual-studio-2015 datetime-format asp.net-web-api2
Oct 10 '17 at 6:48
source share
1 answer

After a great search, I finally found a solution.

I changed the predefined invalid / invalid characters in my Web.config. Under, the following has been added: <httpRuntime requestPathInvalidCharacters="&lt;,&gt;,%,&amp;,*,\,?" />. <httpRuntime requestPathInvalidCharacters="&lt;,&gt;,%,&amp;,*,\,?" />. I removed : from the standard list of invalid characters.

See this solution for more information.

0
Oct 10 '17 at 9:11 on
source share



All Articles