6

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

StrattonL
  • 708
  • 1
  • 9
  • 24

2 Answers2

2

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

Waqas Anwar
  • 350
  • 5
  • 15
1

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.

CheckRaise
  • 550
  • 2
  • 16