당신은 어느 컨트롤러 수준에 AuthroizeAttribute
를 사용할 수 있습니다
[Authorize]
public class HomeController : Controller
{
// Now all actions require authorization
}
또는 작업 레벨 : 당신보다 정밀한 허가뿐만 아니라 AuthorizeAttribute
constructor에 등 사용자 이름, 역할을 통과 할 수
public class HomeController : Controller
{
public ActionResult Index()
{
// Does not require authorization
}
[Authorize]
public ActionResult PrivateThing()
{
// requires authorization
}
}
.
경우에는, 그러나, 기본 AuthroizeAttribute
은 AuthorizeAttribute
에서 상속하여 항상 자신의 롤 수 있습니다 당신을 위해 작동하지 않습니다
public CustomAuthorizeAttribute : AuthorizeAttribute
{
public override void OnAuthorization(AuthorizationContext filterContext)
{
base.OnAuthorization(filterContext);
// Auhtorization logic here
}
}