开发者

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

开发者 https://www.devze.com 2023-03-02 08:22 出处:网络
I have routes like these: routes.MapPageRoute(\"Survey\", \"Survey\", \"~/Survey/Survey.aspx\") routes.MapPa开发者_如何学编程geRoute(\"Letters\", \"About/Letters\", \"~/Pages/Letters/Letters.aspx\")

I have routes like these:

routes.MapPageRoute("Survey", "Survey", "~/Survey/Survey.aspx")
routes.MapPa开发者_如何学编程geRoute("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.

0

精彩评论

暂无评论...
验证码 换一张
取 消