我尝试使用查询字符串路由到以下页面:
http://sitename/Pages/Pages.aspx?id=1 - route to - http://sitename/testpage1
http://sitename/Pages/Pages.aspx?id=2 - route to - http://sitename/testpage2
我在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");
新闻默认和联系人默认工作正常,但不会丢失查询字符串值的测试页。
答案 0 :(得分:0)
我使用了路线的默认值。可能不是最优雅的解决方案,但它有效:
routes.MapPageRoute("Test2", "TestPage2/{id}", "~/Pages/Pages.aspx", true,
new RouteValueDictionary {{"id","2"}});