Если у вас есть определенный набор хранилищ или способ их проверки, вы можете добавить ограничение к маршруту.
Чтобы добавить общее ограничение с предикатом соответствия
public class ServerRouteConstraint : IRouteConstraint
{
private readonly Func<Uri, bool> _predicate;
public ServerRouteConstraint(Func<Uri, bool> predicate)
{
this._predicate = predicate;
}
public bool Match(HttpContextBase httpContext, Route route, string parameterName,
RouteValueDictionary values, RouteDirection routeDirection)
{
return this._predicate(httpContext.Request.Url);
}
}
, а затемв маршрут добавьте параметр
routes.MapRoute(
name: "StoreSearch",
url: "{storeName}",
defaults: new { controller = "Search", action = "Store" }, constraints:
//this could be new { controller ="pattern" }
new {
serverRoute = new ServerRouteConstraint(url =>
{
//this will check that the route starts with a specific string in this case Settings
return url.PathAndQuery.StartsWith("/Settings",
StringComparison.InvariantCultureIgnoreCase);
})
});
. Например, проверьте: https://www.c -sharpcorner.com / UploadFile / dacca2 / route-constraints-in-mvc /
Кроме того, маршруты должны быть добавлены от наиболее специфических к наиболее общим.