Skip to content

Constraints

Mariusz Kerl edited this page Jul 2, 2018 · 1 revision

It is possible to make subdomain constrained.
For example if we want to make guid constraint on subdomain we could do:

public void Configure(IApplicationBuilder app)
{
    //...
    app.UseMvc(routes =>
    {
        var hostnames = new[] { "localhost:54575" };

        routes.MapSubdomainRoute(
            hostnames,
            "TenantInSubdomain",
            "{tenant:guid}",
            "{controller}/{action}",
            new { controller = "Home", action = "Index" });
    });
}

Now tenant can be only guid but you cannot use guid with curly braces since they are not allowed in hostname.
Constraints as an object are also supported: new { tenant = new GuidRouteConstraint()}.

Supported constraints:

Constraint Comments
int negative not allowed
bool
guid curly braces not allowed
long negative not allowed
minlength(value)
maxlength(value)
length(value)
length(min, max)
min(value)
max(value)
range(min,max)
alpha
regex(expression)
datetime not allowed
decimal not allowed
double not allowed
float not allowed

More info: Microsoft's Constraints Page

Clone this wiki locally