I have this route:
{controller}/{id}/{action}
Because I think it makes more sense from RESTful perspective.
The problem is that id
can contain slashes (/
) and those are treated as route separators even when encoded as "%2F". Even when I have this Web.config section in place:
<uri>
<schemeSettings>
<add name="http" genericUriParserOptions="DontUnescapePathDotsAndSlashes" />
<add name="https" genericUriParserOptions="DontUnescapePathDotsAndSlashes" />
</schemeSettings>
</uri>
Because I have id
in the middle I can't employ {*id}
approach which captures the rest of the route including the action
.
It looks like my only option is to encode /
into an RFC compliant character like !
, however I do not want to do it using ad-hoc custom code inside controller. I want controller to receive id
intact, already decoded. And I want my Url.Action
to generate properly encoded URL. Is that too much to ask from MVC, or do I need to scatter ActionFilters and custom URL helpers around?
The only way I could find is to throw in a custom IRouteConstraint
to manipulate the RouteValueDictionary
it receives. That sounds like a dirty hack though: a constraint manipulating its input. God knows its side effects. Do you think this is a sane enough idea, or is there a better mechanism in ASP.NET MVC allowing that?
EDIT: This workaround only works when parsing the route, not when generating one.