You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add exhaustive list of default route constraints (#35838)
* Add exhaustive list of default route constraints
* improve readability of route constraint notes for file and nonfile
Co-authored-by: Luke Latham <[email protected]>
* Update aspnetcore/fundamentals/routing.md
---------
Co-authored-by: Luke Latham <[email protected]>
Copy file name to clipboardExpand all lines: aspnetcore/fundamentals/routing.md
+24-22Lines changed: 24 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -499,28 +499,30 @@ Route constraints execute when a match has occurred to the incoming URL and the
499
499
> [!WARNING]
500
500
> Don't use constraints for input validation. If constraints are used for input validation, invalid input results in a `404` Not Found response. Invalid input should produce a `400` Bad Request with an appropriate error message. Route constraints are used to disambiguate similar routes, not to validate the inputs for a particular route.
501
501
502
-
The following table demonstrates example route constraints and their expected behavior:
503
-
504
-
| constraint | Example | Example Matches | Notes |
|`int`|`{id:int}`|`123456789`, `-123456789`| Matches any integer |
507
-
|`bool`|`{active:bool}`|`true`, `FALSE`| Matches `true` or `false`. Case-insensitive |
508
-
|`datetime`|`{dob:datetime}`|`2016-12-31`, `2016-12-31 7:32pm`| Matches a valid `DateTime` value in the invariant culture. See preceding warning. |
509
-
|`decimal`|`{price:decimal}`|`49.99`, `-1,000.01`| Matches a valid `decimal` value in the invariant culture. See preceding warning. |
510
-
|`double`|`{weight:double}`|`1.234`, `-1,001.01e8`| Matches a valid `double` value in the invariant culture. See preceding warning. |
511
-
|`float`|`{weight:float}`|`1.234`, `-1,001.01e8`| Matches a valid `float` value in the invariant culture. See preceding warning. |
512
-
|`guid`|`{id:guid}`|`CD2C1638-1638-72D5-1638-DEADBEEF1638`| Matches a valid `Guid` value |
513
-
|`long`|`{ticks:long}`|`123456789`, `-123456789`| Matches a valid `long` value |
514
-
|`minlength(value)`|`{username:minlength(4)}`|`Rick`| String must be at least 4 characters |
515
-
|`maxlength(value)`|`{filename:maxlength(8)}`|`MyFile`| String must be no more than 8 characters |
516
-
|`length(length)`|`{filename:length(12)}`|`somefile.txt`| String must be exactly 12 characters long |
517
-
|`length(min,max)`|`{filename:length(8,16)}`|`somefile.txt`| String must be at least 8 and no more than 16 characters long |
518
-
|`min(value)`|`{age:min(18)}`|`19`| Integer value must be at least 18 |
519
-
|`max(value)`|`{age:max(120)}`|`91`| Integer value must be no more than 120 |
520
-
|`range(min,max)`|`{age:range(18,120)}`|`91`| Integer value must be at least 18 but no more than 120 |
521
-
|`alpha`|`{name:alpha}`|`Rick`| String must consist of one or more alphabetical characters, `a`-`z` and case-insensitive. |
522
-
|`regex(expression)`|`{ssn:regex(^\\d{{3}}-\\d{{2}}-\\d{{4}}$)}`|`123-45-6789`| String must match the regular expression. See tips about defining a regular expression. |
523
-
|`required`|`{name:required}`|`Rick`| Used to enforce that a non-parameter value is present during URL generation |
502
+
The following table demonstrates the default route constraints and their expected behavior:
503
+
504
+
| constraint | Example | Example Matches | Notes |
|`int`|`{id:int}`|`123456789`, `-123456789`| Matches any integer |
507
+
|`bool`|`{active:bool}`|`true`, `FALSE`| Matches `true` or `false`. Case-insensitive |
508
+
|`datetime`|`{dob:datetime}`|`2016-12-31`, `2016-12-31 7:32pm`| Matches a valid `DateTime` value in the invariant culture. See preceding warning |
509
+
|`decimal`|`{price:decimal}`|`49.99`, `-1,000.01`| Matches a valid `decimal` value in the invariant culture. See preceding warning |
510
+
|`double`|`{weight:double}`|`1.234`, `-1,001.01e8`| Matches a valid `double` value in the invariant culture. See preceding warning |
511
+
|`float`|`{weight:float}`|`1.234`, `-1,001.01e8`| Matches a valid `float` value in the invariant culture. See preceding warning |
512
+
|`guid`|`{id:guid}`|`CD2C1638-1638-72D5-1638-DEADBEEF1638`| Matches a valid `Guid` value |
513
+
|`long`|`{ticks:long}`|`123456789`, `-123456789`| Matches a valid `long` value |
514
+
|`minlength(value)`|`{username:minlength(4)}`|`Rick`| String must be at least 4 characters |
515
+
|`maxlength(value)`|`{filename:maxlength(8)}`|`MyFile`| String must be no more than 8 characters |
516
+
|`length(length)`|`{filename:length(12)}`|`somefile.txt`| String must be exactly 12 characters long |
517
+
|`length(min,max)`|`{filename:length(8,16)}`|`somefile.txt`| String must be at least 8 and no more than 16 characters long |
518
+
|`min(value)`|`{age:min(18)}`|`19`| Integer value must be at least 18 |
519
+
|`max(value)`|`{age:max(120)}`|`91`| Integer value must be no more than 120 |
520
+
|`range(min,max)`|`{age:range(18,120)}`|`91`| Integer value must be at least 18 but no more than 120 |
521
+
|`alpha`|`{name:alpha}`|`Rick`| String must consist of one or more alphabetical characters, `a`-`z` and case-insensitive |
522
+
|`regex(expression)`|`{ssn:regex(^\\d{{3}}-\\d{{2}}-\\d{{4}}$)}`|`123-45-6789`| String must match the regular expression. See tips about defining a regular expression |
523
+
|`required`|`{name:required}`|`Rick`| Used to enforce that a non-parameter value is present during URL generation |
524
+
|`file`|`{filename:file}`|`myfile.txt`| String can contain path segments, but its last segment must have a dot (`.`) and be followed by one or more non-dot characters |
525
+
|`nonfile`|`{page:nonfile}`|`PageName`| String must not have a dot in its last path segment that is followed by one or more non-dot (`.`) characters |
0 commit comments