【发布时间】:2012-01-05 00:25:13
【问题描述】:
我正在使用 asp.net 4.0 网络表单项目和路由。我需要知道处理请求的实际页面。假设我的路由 url 是这样的
http://mysite.com/product/audi 基本上我有 product.aspx 页面,并且 audi 作为查询字符串值传递。实际上 product.aspx 正在处理请求。我可以以编程方式提取页面名称和查询字符串名称和数据吗?因此,我可以稍后构建 url,例如
http://mysite.com/product.aspx?cat=audi
请帮助我使用路由 url 中的查询字符串构建 url。 谢谢
添加部分
当我们像这样在 global.asax 中映射路线时
`protected void Application_Start(object sender, EventArgs e)
{
RegisterRoutes(RouteTable.Routes);
}
public static void RegisterRoutes(RouteCollection routes)
{
routes.MapPageRoute("","Product/{category}","~/Product.aspx");
}
然后我们得到类似http://www.mysite.com/products/software 的路由路径,但内部url 看起来像http://www.mysite.com/products.aspx?category=software。所以我只需要反转。我会将http://www.mysite.com/products/software 之类的 url 传递给任何例程,并且例程会像http://www.mysite.com/products.aspx?category=software 一样将 url 返回给我。告诉我我该怎么做。
【问题讨论】:
-
我可以在 Page.RouteData.Values 中构造 url 循环吗? foreach (KeyValuePair
kvp in Page.RouteData.Values) { lblAllValues.Text += "Key: " + kvp.Key + " Value: " + kvp.Value + "
"; } vbcity.com/blogs/dowhilesomething/archive/2010/05/15/…