How do I redirect a route to another route in ASP.NET web forms?
Asked Answered
M

2

7

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

Microcosm answered 3/5, 2011 at 22:45 Comment(0)
B
3

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

Berwickupontweed answered 13/6, 2012 at 17:2 Comment(0)
T
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.

Translation answered 6/5, 2011 at 15:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.