2009-08-17 63 views
37

我有这个在我的Global.asax.cs:RedirectToRoute应该如何使用?

routes.MapRoute("BetaAccess", "beta-access", new { controller = "Beta", action = "Index" }); 

这在我的控制器(在HomeController的索引操作)和它肯定是击中:

RedirectToRoute("BetaAccess"); 

,但仍没有发生重定向...它只是进入正常的主页。我用错了吗?

另外,我可以做的Response.Redirect( “〜/β-访问”),并进入公测网页...

回答

44

RedirectToRoute返回RedirectToRouteResult。试试这个。

return RedirectToRoute("BetaAccess"); 
+49

哦,我是'tard。谢谢。 – 2009-08-17 20:58:01

+3

我必须投票评论,让我发笑。 (不用担心,这是一个容易犯的错误。:) – 2009-08-18 00:56:21

4

这会重定向你。

Response.RedirectToRoute("BetaAccess"); 
Response.End(); 
+0

我也遇到了麻烦....我在webForms中使用它,但我得到这个错误:“名为'学生/基本信息'的路线不能在路由集合中找到 参数名称:name“...我定义了如下路由:”Routes.MapPageRoute(“StudentsBasicData”,“Students/Basic-Information”,“〜/ Student/BasicInfo/BasicInfoCompletion.aspx “);” – Lucky 2013-05-18 08:05:35