Mor*_*son 3 c# asp.net-membership asp.net-mvc-3
在我的MVC 3 .net应用程序中,我有两个区域,一个叫Admin,另一个叫Student.我使用内置的会员系统进行用户身份验证,并在两个区域之间进行统一.问题是,我想使用区域特定的登录页面,因为这两个区域在设计上有很多不同(学生针对的是移动设备).据我所知,我只能在Web.config中为应用程序指定一个登录页面,如下所示:
<authentication mode="Forms">
<forms loginUrl="~/Admin/Account/LogOn" timeout="2880" />
</authentication>`
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我如何为同一会员系统实现多个登录页面?
您只能为ASP.NET应用程序指定1个登录URL,因此您需要执行以下操作:
在每个Araa中都有一个Login控制器以及应用程序根目录中的主Login控制器.
在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>
Run Code Online (Sandbox Code Playgroud)
在Web.Config中配置表单身份验证以使用根应用程序中的Login控制器:
<forms loginUrl="~/LogOn" timeout="2880" />
Run Code Online (Sandbox Code Playgroud)
然后在根登录控制器中,在默认操作中执行以下操作:
//
// 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.
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2765 次 |
| 最近记录: |