且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

具有不同的登录页面不同的ASP.NET MVC 3区

更新时间:2023-02-16 07:54:47

我不知道.NET处理这个给你,但你可以创建一个自定义的AuthorizationAttribute

I'm not aware of .NET handling this for you but you could create a custom 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);

  }

}

这是添加到您的控制器/动作

An add that to your controllers/actions

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