身份验证 - 路由上的asp mvc区域问题

时间:2012-01-29 14:35:18

标签: asp.net-mvc asp.net-mvc-3 routing asp.net-mvc-routing asp.net-mvc-areas

我再次遇到路由问题:) 当我运行应用程序时,如果用户未经过身份验证,则会将其重定向到登录页面。 我用FormsAuthentication 登录页面位于区域帐户中 当前网址为

http://localhost:38962/Account/Home/Index?ReturnUrl=%2f

从网络配置设置

<authentication mode="Forms">
      <forms loginUrl="~/Account/Home/Index" timeout="2880" />
    </authentication>

我尝试在AccountAreaRegistration类中设置路由

context.MapRoute("home_login",
                "",
                new { area = "Account", controller = "Home", action = "Index", ReturnUrl = UrlParameter.Optional });

和其他一些设置bu无法获取登录页面,而URL仍然只是

http://localhost:38962

我还在AccountAreaRegister中有路由

context.MapRoute(
                "Account_default",
                "Account/{controller}/{action}/{id}",
                new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );

更新1

   routes.MapRoute(
                    "Default",
                    "{controller}/{action}/{cityId}",
                    new { area = "MainArea", controller = "Home", action = "Index", cityId = UrlParameter.Optional },
                    new string[] { "MCN.WebUI.Areas.MainArea.Controllers" }).DataTokens.Add("area", "MainArea");

1 个答案:

答案 0 :(得分:1)

修复你的MapRoute函数调用,第二个参数应该是

Account/{controller}/{action}

删除第三个参数中的区域

<强>的web.config

 <authorization>
      <deny users="?"/>
    </authorization>
相关问题