问题
I'm using catch-all routing with MVC to provide a path to a resource in our application. It looks like such:
_routes.MapRoute(null, "Resource/{*resourcePath}", new {
controller = "Resource",
action = "Open"
});
And the action is something like
public ActionResult Open(string resourcePath) {
string[] path = resourcePath.Split('/');
}
Hitting it with a nice and friendly URL it works fine
/Resource/Path/To/Resource
path = ["Path", "To", "Resource"]
But when I have a resource name with a forward slash in it (which I, of course, escape), it treats the escaped slash as part of the path
/Resource/Path/To/Resource%2FWith%2FSlashes
path = ["Path", "To", "Resource", "With", "Slashes"]
I expected ["Path", "To", "Resource/With/Slashes"]
I tried double escaping, only to have ASP.NET complain about double-escaping for security reasons, and I don't think I should open that can of worms.
Is there any way I can make the catch-all route not unescape the slash?
来源:https://stackoverflow.com/questions/19698709/asp-net-catch-all-routing-and-escaping-forward-slashes