-
Notifications
You must be signed in to change notification settings - Fork 9.8k
/
RouteOptions.cs
119 lines (104 loc) · 4.78 KB
/
RouteOptions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using Microsoft.AspNetCore.Routing.Constraints;
namespace Microsoft.AspNetCore.Routing
{
public class RouteOptions
{
private IDictionary<string, Type> _constraintTypeMap = GetDefaultConstraintMap();
private ICollection<EndpointDataSource> _endpointDataSources = default!;
/// <summary>
/// Gets a collection of <see cref="EndpointDataSource"/> instances configured with routing.
/// </summary>
internal ICollection<EndpointDataSource> EndpointDataSources
{
get
{
Debug.Assert(_endpointDataSources != null, "Endpoint data sources should have been set in DI.");
return _endpointDataSources;
}
set => _endpointDataSources = value;
}
/// <summary>
/// Gets or sets a value indicating whether all generated paths URLs are lowercase.
/// Use <see cref="LowercaseQueryStrings" /> to configure the behavior for query strings.
/// </summary>
public bool LowercaseUrls { get; set; }
/// <summary>
/// Gets or sets a value indicating whether a generated query strings are lowercase.
/// This property will not be used unless <see cref="LowercaseUrls" /> is also <c>true</c>.
/// </summary>
public bool LowercaseQueryStrings { get; set; }
/// <summary>
/// Gets or sets a value indicating whether a trailing slash should be appended to the generated URLs.
/// </summary>
public bool AppendTrailingSlash { get; set; }
/// <summary>
/// Gets or sets a value that indicates if the check for unhandled security endpoint metadata is suppressed.
/// <para>
/// Endpoints can be associated with metadata such as authorization, or CORS, that needs to be
/// handled by a specific middleware to be actionable. If the middleware is not configured, such
/// metadata will go unhandled.
/// </para>
/// <para>
/// When <see langword="false"/>, prior to the execution of the endpoint, routing will verify that
/// all known security-specific metadata has been handled.
/// Setting this property to <see langword="true"/> suppresses this check.
/// </para>
/// </summary>
/// <value>Defaults to <see langword="false"/>.</value>
/// <remarks>
/// This check exists as a safeguard against accidental insecure configuration. You may suppress
/// this check if it does not match your application's requirements.
/// </remarks>
public bool SuppressCheckForUnhandledSecurityMetadata { get; set; }
public IDictionary<string, Type> ConstraintMap
{
get
{
return _constraintTypeMap;
}
set
{
if (value == null)
{
throw new ArgumentNullException(nameof(ConstraintMap));
}
_constraintTypeMap = value;
}
}
private static IDictionary<string, Type> GetDefaultConstraintMap()
{
return new Dictionary<string, Type>(StringComparer.OrdinalIgnoreCase)
{
// Type-specific constraints
{ "int", typeof(IntRouteConstraint) },
{ "bool", typeof(BoolRouteConstraint) },
{ "datetime", typeof(DateTimeRouteConstraint) },
{ "decimal", typeof(DecimalRouteConstraint) },
{ "double", typeof(DoubleRouteConstraint) },
{ "float", typeof(FloatRouteConstraint) },
{ "guid", typeof(GuidRouteConstraint) },
{ "long", typeof(LongRouteConstraint) },
// Length constraints
{ "minlength", typeof(MinLengthRouteConstraint) },
{ "maxlength", typeof(MaxLengthRouteConstraint) },
{ "length", typeof(LengthRouteConstraint) },
// Min/Max value constraints
{ "min", typeof(MinRouteConstraint) },
{ "max", typeof(MaxRouteConstraint) },
{ "range", typeof(RangeRouteConstraint) },
// Regex-based constraints
{ "alpha", typeof(AlphaRouteConstraint) },
{ "regex", typeof(RegexInlineRouteConstraint) },
{"required", typeof(RequiredRouteConstraint) },
// Files
{ "file", typeof(FileNameRouteConstraint) },
{ "nonfile", typeof(NonFileNameRouteConstraint) },
};
}
}
}