Skip to main content
Added the month value to 13, so that it will be easier to understand the month range is above 12 and that's why it is partially working.
Source Link

I have used two regular expressions, one to limit the first parameter(year) to 4 digits and the second(month) to limit the second parameter to 2 digits.

[Route("movies/released/{year:regex(\\d{4})}/{month:regex(\\d{2}):range(1, 12)}")] public ActionResult ByReleaseDate(int year, int month) { return Content($"{year}/{month}"); } 

This partially works, when I navigate to /movies/released/2017/11313 I am shown a 404.

But when I navigate to /movies/released/200017/03 a 404 is not produced.

I have used two regular expressions, one to limit the first parameter to 4 digits and the second to limit the second parameter to 2 digits.

[Route("movies/released/{year:regex(\\d{4})}/{month:regex(\\d{2}):range(1, 12)}")] public ActionResult ByReleaseDate(int year, int month) { return Content($"{year}/{month}"); } 

This partially works, when I navigate to /movies/released/2017/113 I am shown a 404.

But when I navigate to /movies/released/200017/03 a 404 is not produced.

I have used two regular expressions, one to limit the first parameter(year) to 4 digits and the second(month) to limit the second parameter to 2 digits.

[Route("movies/released/{year:regex(\\d{4})}/{month:regex(\\d{2}):range(1, 12)}")] public ActionResult ByReleaseDate(int year, int month) { return Content($"{year}/{month}"); } 

This partially works, when I navigate to /movies/released/2017/13 I am shown a 404.

But when I navigate to /movies/released/200017/03 a 404 is not produced.

Source Link
user7131941
user7131941

MVC5 attribute routing regular expression not producing desired result

I have used two regular expressions, one to limit the first parameter to 4 digits and the second to limit the second parameter to 2 digits.

[Route("movies/released/{year:regex(\\d{4})}/{month:regex(\\d{2}):range(1, 12)}")] public ActionResult ByReleaseDate(int year, int month) { return Content($"{year}/{month}"); } 

This partially works, when I navigate to /movies/released/2017/113 I am shown a 404.

But when I navigate to /movies/released/200017/03 a 404 is not produced.