在我的 MVC 3 .net 应用程序中,我有两个区域,一个称为 Admin,一个称为 Student。我使用内置的成员(member)系统进行用户身份验证,并且它在两个区域之间是统一的。问题是,我想使用区域特定的登录页面,因为这两个区域在设计上有很大不同(学生针对移动设备)。据我所知,我只能在 Web.config 中为应用程序指定一个登录页面,如下所示:
<authentication mode="Forms">
<forms loginUrl="~/Admin/Account/LogOn" timeout="2880" />
</authentication>`
在这种情况下,如何为同一个成员(member)系统实现多个登录页面?
最佳答案
您只能为 ASP.NET 应用程序指定 1 个登录 URL,因此您需要执行以下解决方法:
在每个 Araa 中,在应用程序的根目录中都有一个登录 Controller 和一个主登录 Controller 。
在 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 中配置表单例份验证以在根应用程序中使用登录 Controller :
<forms loginUrl="~/LogOn" timeout="2880" />
然后在根登录 Controller 中执行以下默认操作:
//
// 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.
}
关于c# - 区域特定登录页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5660337/