22 lines
726 B
C#
22 lines
726 B
C#
namespace NoticeBoard.Routing;
|
|
|
|
public class DeviceSlugConstraint : IRouteConstraint
|
|
{
|
|
private static readonly HashSet<string> ReservedPaths = new(StringComparer.OrdinalIgnoreCase)
|
|
{
|
|
"admin", "api", "account", "d", "error", "css", "js", "lib", "uploads", "favicon.ico"
|
|
};
|
|
|
|
public bool Match(HttpContext? httpContext, IRouter? route, string routeKey,
|
|
RouteValueDictionary values, RouteDirection routeDirection)
|
|
{
|
|
if (values.TryGetValue(routeKey, out var value) && value is string slug)
|
|
{
|
|
if (ReservedPaths.Contains(slug))
|
|
return false;
|
|
return slug.All(c => char.IsLetterOrDigit(c) || c == '-');
|
|
}
|
|
return false;
|
|
}
|
|
}
|