c# - Regex in Route attribute - RESTful API ASP.NET Web API -


I have a problem with regular expression in the root attribute. I want to create a RESTABLE API, where you can filter the results You can specify the start date and end date in the URL. What I've done so far:

  [HttpGet] [root ("date / {start date: datetime: regex (\\ d {4} - \\ d {2} - \ \ D {{End}: {{end_date: datetime: regex (\\ d {4} - \\ d {2} - \\ d {2})} ")] [root (" date / {startDate: date: regular Expression (\\ d {4} / \\ d {2} / \\ d {2})} / {* ENDDATE: Date: Regular Expression (\\ d {4} / \\ d {2} / \ \ D {2})} ")] Public IEnumerable & lt; Recommendation & gt; GetRecommendationByDate (DateTime StartDate, Datetime? AndDet) {var output = DB. Where (R = & gt; RiPrinted == True & amp; amp; amp; R.CreditedDetate.Cartrate> & gt; & amp; amp; R.R.Comp.net (EnddateHouse Value? AndDet. Value: Datetime.now) 0). Orderbidescosing (R => R.Last Modified) .Oolist (); Return output; }  

It does not work as to how I want it, because the second should be the ultimate faucet. When I only pass the start date, I am getting 404. Format also with slash does not work at all. What am I doing wrong? I thought * that the parameter is null ...

=== EDIT ===

My URLs are both match:

https: // Local Host: Post / API / Recommendations / Date / 10/07/2013/1/08/2014 - Not working

https: // Local Host: Post / API / Recommendations / Date / 10 -07 -2013 / 1-08-2014 - work

and with the tapable second parameter:

https: // localhost: post / api / recommendations / date / 10 / 07/2013 - does not work

https: // localhost: post / api / recommendations / date / 10-07-2013 - does not work

type your route template

  [route ("API / recommendations / date / {startdate: date: rayx (\\) D {2} - \\ d {2} - \\ d {4})} / {ENDDATE: Date: Regular Expression (\\ d {2} - \\ d {2} - \\ d {4}) ?} ")]  

and you should provide a default value for the nullable parameter

  public IEnumerable & lt; Recommendation & gt; For slash, slash URL is used to isolate segments, which means that a single segment can not have a slash until it is encoded. 


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -