URL路由未知数量的PARAMS [英] Url Routing for unknown number of params
问题描述
我已经看到了这个帖子:<一href=\"http://stackoverflow.com/questions/3371615/mvc-handler-for-an-unknown-number-of-optional-parameters\">MVC处理器未知数可选参数的,但它是MVC似乎并没有为我工作,我得到一个错误:
I have seen this post: MVC Handler for an unknown number of optional parameters but it's for MVC and doesn't seem to work for me as I get an error:
A path segment that contains more than one section, such as a literal section or a parameter, cannot contain a catch-all parameter.
我希望能够有一个网址参数的不确定的量,我有以下途径:
I want to be able to have an indeterminate amount of params in a Url, I have the following route:
RouteCollection.MapPageRoute("ManyParam", "{*params}.html", "~/Default.aspx");
这似乎也触发上述错误信息。
This also seems to trigger the error message above.
如何建立一个路由在Web窗体(不MVC)。
How can I set up a route to have an unknown number of parameters in web forms (not MVC).
我想实现以下网址:
www.example.com/some-thing.html
www.example.com/some-thing/else.html
www.example.com/and/some-thing/else.html
www.example.com/1/2/3/4/5/6.html
修改
看来,当我使用的工作如下:
It seems to work when I use the following:
RouteCollection.MapPageRoute("ManyParam", "{*params}", "~/Default.aspx");
问题是与这是它不允许 html的
末
推荐答案
下面未经测试的路线 - 通配符一个人均是网址的绝对最后一部分。如此给力。html的在你需要使用约束(5参数)结束。
Untested route below - the wildcard one have to be absolutely last portion of Url. So to force ".html" at the end you need to use constraint (5th argument).
routes.MapPageRoute(
"ManyParam",
"{*path}",
"~/Default.aspx",
false,
new RouteValueDictionary(),
new RouteValueDictionary { { "path", @".*\.html" } }
);
这篇关于URL路由未知数量的PARAMS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!