ASP.NET Catch all routing and escaping forward slashes

南笙酒味 提交于 2019-12-07 13:57:54

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!