Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Choose proper route w/ constraints #494

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,15 @@ protected virtual string ResolveRouteUrl(ISiteMapNode node, string area, string
// the current controller name will cause the route match to fail if the current controller is not the same
// as the destination controller.
routeValueDictionary.Remove("route");
routeValueDictionary.Remove("controller");
routeValueDictionary.Remove("action");
// However, removing controller and action potentially have the unintended side-effect of preventing
// routes from matching when the route depends on either to satisfy a constraint.
// It is possible that these values should NEVER be removed to allow proper construction of a
// named route without defaults or with unspecified tokens.
//routeValueDictionary.Remove("controller")
//routeValueDictionary.Remove("action")
var route = urlHelper.RouteCollection[node.Route] as Route;
if (!(route?.Constraints.ContainsKey("controller") ?? false)) routeValueDictionary.Remove("controller");
if (!(route?.Constraints.ContainsKey("action") ?? false)) routeValueDictionary.Remove("action");
result = urlHelper.RouteUrl(node.Route, routeValueDictionary);
}
else
Expand Down