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:
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"}});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.