为不同的ASP.NET MVC 3区域提供不同的登录页面

可以为不同的ASP.NET MVC3区域使用不同的登录URL吗?

例如我想为管理员和数据输入运算符提供不同的登录页面

我在每个区域的视图部分看到一个web.config,我已经尝试过:

<authentication mode="Forms">
    <forms loginUrl="~/Administration/Account/logon" timeout="2880" />
</authentication>

但它不能奏效。

干杯。

解决方法

我不知道.NET处理这个,但你可以创建一个自定义AuthorizationAttribute
public class CustomAuthorization : AuthorizeAttribute {

  public string Url { get; set; }

  public override void OnAuthorization(AuthorizationContext filterContext) {

    if (!filterContext.HttpContext.User.Identity.IsAuthenticated) {
      filterContext.HttpContext.Response.Redirect(Url);
    }
    base.OnAuthorization(filterContext);

  }

}

添加到您的控制器/操作

[CustomAuthorization(Url="/Area/Login")]
public class HomeController {
  //...
}

相关文章

这篇文章主要讲解了“WPF如何实现带筛选功能的DataGrid”,文...
本篇内容介绍了“基于WPF如何实现3D画廊动画效果”的有关知识...
Some samples are below for ASP.Net web form controls:(fr...
问题描述: 对于未定义为 System.String 的列,唯一有效的值...
最近用到了CalendarExtender,结果不知道为什么发生了错位,...
ASP.NET 2.0 page lifecyle ASP.NET 2.0 event sequence cha...