1

新的 ASP.NET 路由非常适合简单的路径样式 URL,但如果您想使用如下 URL:

http://example.com/items/search.xhtml?term=Text+to+find&page=2

您是否必须在验证中使用 catch all 参数?

4

4 回答 4

3

您也可以将查询字符串参数与路由匹配,如果您只想捕获添加参数所需的所有内容,如下所示:

{*contentUrl}

这会将 url 的其余部分填充到该变量中。

于 2008-10-15T17:20:48.647 回答
2

路由中未列出的任何视图数据项都会自动映射到查询字符串,因此如果将“items/search.xhtml”映射到操作:

Search(string term, int page)

然后你应该得到你正在寻找的结果。

于 2008-10-16T08:11:27.333 回答
0

我也无法将编码的 URL 作为路由参数传递给路由。

您不能在 URL 中使用 url 编码字符,但可以在查询字符串中使用。

因此,我需要我的路线也有一个查询字符串元素。

假设我有一条路线:

MapPageRoute("myroute", "myroute/{x}", "~/routehander.aspx")

但我希望它采用以下形式:

http://mywebsite.com/myroute/{x}?url=myurl

我们可以完成这个:

Dim x as integer = 12
Dim rvd As New Routing.RouteValueDictionary
rvd.Add("x", x)
rvd.Add("url", Server.UrlEncode("/default.aspx"))
HttpContext.Current.ApplicationInstance.Response.RedirectToRoutePermanent("myroute", rvd)

这会将我们重定向到以下网址:

http://mywebsite.com/myroute/12?url=%252fdefault.aspx
于 2011-10-11T11:49:16.953 回答
0

你仍然可以使用Request.QueryString["some_value"];

于 2012-03-12T19:40:11.783 回答