2011-04-14 72 views
3

在我的MVC 3 .net应用程序中,我有两个区域,一个叫Admin,一个叫Student。我使用内置的会员系统进行用户验证,并在两个区域之间进行统一。问题是,我想使用区域特定的登录页面,因为这两个区域在设计上有很大不同(Student是针对移动设备的)。据我所知,我只能指定一个登录页面Web.config中的应用,像这样:区域特定的登录页面

<authentication mode="Forms"> 
    <forms loginUrl="~/Admin/Account/LogOn" timeout="2880" /> 
</authentication>` 

在这种情况下,我将如何实现对同一会员制度若干登录页面?

回答

6

只能有一个ASP.NET应用程序指定1个登录网址,所以你需要做以下解决方法:

在每个ARAA有一个登录控制器,以及在主登录控制器应用程序的根。

在web.config中,请确保您有:

<configuration> 
    <location path="/Admin/Account/LogOn"> 
    <system.web> 
     <authorization> 
     <allow users="?"/> 
     </authorization> 
    </system.web> 
    </location> 
    <location path="/Student/Account/LogOn"> 
    <system.web> 
     <authorization> 
     <allow users="?"/> 
     </authorization> 
    </system.web> 
    </location> 
</configuration> 

在你的web.config配置窗体身份验证的根应用程序中使用的登录控制:

<forms loginUrl="~/LogOn" timeout="2880" /> 

然后在根登录控制器在默认操作中执行以下操作:

// 
// GET: /LogOn 
public ActionResult Index(string returnUrl) 
{ 
    var area = returnUrl.TrimStart('/').Split('/').FirstOrDefault(); 

    if (!string.IsNullOrEmpty(area)) 
     return RedirectToAction("LogOn", "Account", new { area }); 

    // TODO: Handle what happens if no area was accessed. 
} 
4

您应该阅读this白皮书。那里描述了你的问题的解决方案。