Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 576
StrattonL Avatar asked May 03 '11 22:05

StrattonL


People also ask

Which of the following methods can you use to create routes in a Web Forms application in ASP NET MVC?

Routing in ASP.NET MVC cs file in App_Start Folder, You can define Routes in that file, By default route is: Home controller - Index Method.

What is the difference between routing and URL rewriting?

ASP.NET routing is used to dispatch a request to a handler based on the requested URL path. As opposed to URL rewriting, the routing module knows about the handlers and selects the handler that should generate a response for the requested URL. You can think of ASP.NET routing as an advanced handler-mapping mechanism.

What is redirect to route in MVC?

RedirectToRoute(String, RouteValueDictionary)Redirects to the specified route using the route name and route dictionary.

How do I use MapControllerRoute?

MapControllerRoute(name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); The route names give the route a logical name. The named route can be used for URL generation. Using a named route simplifies URL creation when the ordering of routes could make URL generation complicated.


1 Answers

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

like image 135
Waqas Anwar Avatar answered Oct 24 '22 12:10

Waqas Anwar