I have routes like these:
routes.MapPageRoute("Survey", "Survey", "~/Survey/Survey.aspx")
routes.MapPageRoute("Letters", "About/Letters", "~/Pages/Letters/Letters.aspx")
How can I redirect a url like this: /Surveys to the 'Survey' route? So that when the user goes to /surveys it redirects to /Survey. (URLs for the sake of argument)
I'd prefer it if I didn't have to place redirect code in the ASPX file itself, and rather just have the code in the route rule, just keeps it simple and centralized.
Thanks
Luke
You can use something like this
Response.RedirectToRoute("Survey");
the parameter "Survey" is routeName you defined in Global.asax using MapPageRoute. RedirectToRoute also has other overloads that allow you to pass route parameters if required
If you really don't want to create a physical file for /Surveys then you can use IIS url rewriting capabilities to redirect all requests from /Surveys to /Survey. Check out this link to see how to do it in IIS.
来源:https://stackoverflow.com/questions/5876599/how-do-i-redirect-a-route-to-another-route-in-asp-net-web-forms