c# - 区域特定登录页面

标签 c# asp.net-mvc-3 asp.net-membership

在我的 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/

相关文章:

.net - ASP.NET MVC - 临时要求除一页之外的整个站点授权的简便方法

javascript - 从 ASP.NET MVC 3 开始,MicrosoftAjax.js、MicrosoftMvcAjax.js 和 MicrosoftMvcValidation.js 是否已过时?

asp.net - DotNet OpenID 和 ASP.NET 成员(member)资格

c# - Entity Framework - 所有列均无效

c# - ASP.Net MVC3 模型绑定(bind)错误

asp.net - 从 ASP.NET SQL memership DB 中删除失效/丢失的应用程序引用?

c# - 存储过程上的 OdbcCommand - 输出参数出现 "Parameter not supplied"错误

c# - WPF Bing map - 缩放至折线

c# - 方法内修改方法参数或返回结果

c# - "\a"和 Console.Beep() 方法播放相同的哔哔声吗?