I have added a new route to my routing table:
routes.MapRoute(
"ModuleRoute", // Route name
"Module/{href}", // URL with parameters
new { controller = "Module", action = "GetHtml" }// Parameter defaults
);
I need this route to match on the following url structure:
/module/123abc.html
The problem is it also matches on this structure
/module/Launch/123abc.html
Calling link :
<%: Html.ActionLink("Launch", "Launch", new { href = item.Href })%>
How do I stop that from happening? I want he second structure to continue to be matched by the default route. I thought that because the number of parameters are different that this would not be a problem.
How can better filter my route to prevent this?
Thanks!
i agree with Max Toro, i’ve done some testing and that URL doesn’t match
Module/{href}.This:
is actually hitting the default route. You see this if you change the default route to the below (note the id is changed to
hrefso, this proves it is falling through the first route since it gets a proper url (no querystrings)
what it is doing (when you have the usual default route with
id) is that thecontrollerandactionare matched but theidisn’t. This is OK – the route still matches but leaves off theid. All additional values, such as yourhrefare appended as querystring parameters so you end up with:The way to get around it is to add another route similar to the one above that uses
hrefinstead ofidsomething like: