How can we set authorization for a whole area in ASP.NET MVC?

前端 未结 7 1364

I\'ve an Admin area and I want only Admins to enter the area. I considered adding the Authorized attribute to every controller in the Admin area. Isn\'t there an elegant sol

7条回答
  •  悲哀的现实
    2020-12-08 04:38

    .. very crudely I believe you want something like this?

    Quick and dirty role management

    [Authorize(Roles = "Admins")]
    public ActionResult Register()
    {
      ViewData["roleName"] = new SelectList(Roles.GetAllRoles(), "roleName");
      ViewData["PasswordLength"] = MembershipService.MinPasswordLength;
      return View();
    }
    

提交回复
热议问题