FileNameRouteConstraint Class

Definition

Constrains a route parameter to represent only file name values. Does not validate that the route value contains valid file system characters, or that the value represents an actual file on disk.

C#
public class FileNameRouteConstraint : Microsoft.AspNetCore.Routing.IRouteConstraint
C#
public class FileNameRouteConstraint : Microsoft.AspNetCore.Routing.IRouteConstraint, Microsoft.AspNetCore.Routing.Matching.IParameterLiteralNodeMatchingPolicy
Inheritance
FileNameRouteConstraint
Implements

Remarks

This constraint can be used to disambiguate requests for static files versus dynamic content served from the application.

This constraint determines whether a route value represents a file name by examining the last URL Path segment of the value (delimited by /). The last segment must contain the dot (.) character followed by one or more non-(.) characters.

If the route value does not contain a / then the entire value will be interpreted as the last segment.

The FileNameRouteConstraint does not attempt to validate that the value contains a legal file name for the current operating system.

The FileNameRouteConstraint does not attempt to validate that the value represents an actual file on disk.

Examples of route values that will be matched as file names-description

  • /a/b/c.txt : Final segment contains a . followed by other characters.
  • /hello.world.txt : Final segment contains a . followed by other characters.
  • hello.world.txt : Final segment contains a . followed by other characters.
  • .gitignore : Final segment contains a . followed by other characters.

Examples of route values that will be rejected as non-file-names-description

  • /a/b/c : Final segment does not contain a ..
  • /a/b.d/c : Final segment does not contain a ..
  • /a/b.d/c/ : Final segment is empty.
  • : Value is empty

Constructors

Methods

Match(HttpContext, IRouter, String, RouteValueDictionary, RouteDirection)

Determines whether the URL parameter contains a valid value for this constraint.

Explicit Interface Implementations

Applies to

Produk Versi
ASP.NET Core 3.0, 3.1, 5.0, 6.0, 7.0, 8.0, 9.0