简体   繁体   English

使用Web窗体路由时查询字符串丢失

[英]Query string lost when using Web Forms routing

I'm trying to route to the following pages with query strings: 我正在尝试使用查询字符串路由到以下页面:

http://sitename/Pages/Pages.aspx?id=1 - route to - http://sitename/testpage1  
http://sitename/Pages/Pages.aspx?id=2 - route to - http://sitename/testpage2

I'm using Microsoft.AspNet.FriendlyUrls in a webform project: 我在一个Webform项目中使用Microsoft.AspNet.FriendlyUrls:

var settings = new FriendlyUrlSettings();
settings.AutoRedirectMode = RedirectMode.Permanent;
routes.EnableFriendlyUrls(settings);
routes.RouteExistingFiles = true;
routes.MapPageRoute("News Default", "News", "~/news/news.aspx");
routes.MapPageRoute("Contact Default", "Contacts", "~/contacts/contacts.aspx");

routes.MapPageRoute("Test1", "TestPage1", "~/Pages/Pages.aspx?id=1");
routes.MapPageRoute("Test2", "TestPage2", "~/Pages/Pages.aspx?id=2");

The News Default and Contact Default work fine but not the testpages, which lose the query string value. “新闻默认值”和“联系默认值”可以正常工作,但不能运行测试页,因为它们丢失了查询字符串值。

I used a default value for the route. 我为路由使用了默认值。 May not be the most elegant solution, but it works: 可能不是最优雅的解决方案,但它可行:

routes.MapPageRoute("Test2", "TestPage2/{id}", "~/Pages/Pages.aspx", true, 
new RouteValueDictionary {{"id","2"}}); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM