如何在ASP.NET Web表单中将路由重定向到另一个路由? [英] How do I redirect a route to another route in ASP.NET web forms?

查看:95
本文介绍了如何在ASP.NET Web表单中将路由重定向到另一个路由?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的路线:

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

如何将这样的网址重定向:/调查到调查"路线?这样,当用户转到/surveys时,它将重定向到/Survey.(为方便起见,使用网址)

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)

如果我不必将重定向代码放置在ASPX文件本身中,而是将代码包含在路由规则中,则只需将其保持简单且集中即可.

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.

谢谢

卢克

推荐答案

您可以使用类似

Response.RedirectToRoute("Survey");

参数调查"是您使用MapPageRoute在Global.asax中定义的routeName.RedirectToRoute还具有其他重载功能,允许您在需要时传递路由参数

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

这篇关于如何在ASP.NET Web表单中将路由重定向到另一个路由?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆