How to redirect a route to another route in ASP.NET web forms?

I have such routes:

routes.MapPageRoute("Survey", "Survey", "~/Survey/Survey.aspx") routes.MapPageRoute("Letters", "About/Letters", "~/Pages/Letters/Letters.aspx") 

How do I redirect the url like this: / Surveys to the 'Survey' route? Thus, when the user goes to polls, he redirects to / Survey. (Urls for the argument)

I would prefer it if I didn’t have to place the redirect code in the ASPX file itself and rather just have the code in the route rule, it just keeps it simple and centralized.

thanks

Luke

+6
source share
2 answers

You can use something like this

 Response.RedirectToRoute("Survey"); 

the Poll parameter is the NameName that you defined in Global.asax using MapPageRoute. RedirectToRoute also has other overloads that allow you to pass route parameters if required

+2
source

If you really don't want to create a physical file for / Surveys, you can use the IIS URL rewriting capabilities to redirect all requests from / Surveys to / Survey. Check out this link to learn how to do this in IIS.

+1
source

Source: https://habr.com/ru/post/887245/


All Articles