Share via


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.

public ref class FileNameRouteConstraint : Microsoft::AspNetCore::Routing::IRouteConstraint
public class FileNameRouteConstraint : Microsoft.AspNetCore.Routing.IRouteConstraint
public class FileNameRouteConstraint : Microsoft.AspNetCore.Routing.IRouteConstraint, Microsoft.AspNetCore.Routing.Matching.IParameterLiteralNodeMatchingPolicy
type FileNameRouteConstraint = class
    interface IParameterPolicy
    interface IRouteConstraint
type FileNameRouteConstraint = class
    interface IRouteConstraint
    interface IParameterPolicy
type FileNameRouteConstraint = class
    interface IRouteConstraint
    interface IParameterPolicy
    interface IParameterLiteralNodeMatchingPolicy
Public Class FileNameRouteConstraint
Implements IRouteConstraint
Public Class FileNameRouteConstraint
Implements IParameterLiteralNodeMatchingPolicy, IRouteConstraint
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

FileNameRouteConstraint()

Methods

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

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

Explicit Interface Implementations

IParameterLiteralNodeMatchingPolicy.MatchesLiteral(String, String)

Applies to