3 回答

TA貢獻(xiàn)1799條經(jīng)驗(yàn) 獲得超6個(gè)贊
我想向覆蓋[授權(quán)]添加一些內(nèi)容(案例2)
OverrideAuthorizeAttribute和DefaultAuthorizeAttribute可以正常工作,但是我發(fā)現(xiàn)您還可以使用OverrideAuthorizationAttribute來覆蓋更高級(jí)別定義的授權(quán)過濾器。
[Authorize(Roles="user")]
public class HomeController : Controller {
// Available to accounts in the "user" role
public ActionResult AllUsersIndex() {
return View();
}
// Available only to accounts both in the "user" and "admin" role
[Authorize(Roles = "admin")]
public ActionResult AdminUsersIndex() {
return View();
}
// Available to accounts in the "superuser" role even if not in "user" role
[OverrideAuthorization()]
[Authorize(Roles = "superuser")]
public ActionResult SuperusersIndex() {
return View();
}
}
- 3 回答
- 0 關(guān)注
- 675 瀏覽
添加回答
舉報(bào)