开发者

MVC3 MapRoute, parameter with slashes

开发者 https://www.devze.com 2023-03-17 01:48 出处:网络
How would i create a MapRoute that accepts slashes without considering it a new parameter? If the url is

How would i create a MapRoute that accepts slashes without considering it a new parameter? If the url is

http://localhost/root/p1/default.aspx

I want one parameter to pick up everything after localhost (root/p1/default.aspx). Normally it would take three parameters for this because there are two slashes, and maproute separates the pa开发者_JS百科rameters by slash. So if the route looks something like

routes.MapRoute(
   "URLMapRoute",
   "{path}",
   new { controller = "Home", action = "Index", path = "default.aspx" }
);

then {path} picks up everything, even though the url contains slashes.


You could use a catchall route:

routes.MapRoute(
    "URLMapRoute",
    "{*path}",
    new { controller = "Home", action = "Index", path = "default.aspx" }
);

and then:

public ActionResult Index(string path)
{
    ...
}
0

精彩评论

暂无评论...
验证码 换一张
取 消