亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Asp.net MVC4:對控制器和操作均進行授權

Asp.net MVC4:對控制器和操作均進行授權

動漫人物 2019-11-28 09:55:44
如果我在控制器和操作上都具有Authorize屬性,哪個將生效?還是會同時生效?
查看完整描述

3 回答

?
哈士奇WWW

TA貢獻1799條經驗 獲得超6個贊

我想向覆蓋[授權]添加一些內容(案例2)


OverrideAuthorizeAttribute和DefaultAuthorizeAttribute可以正常工作,但是我發現您還可以使用OverrideAuthorizationAttribute來覆蓋更高級別定義的授權過濾器。


[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();

    }

}


查看完整回答
反對 回復 2019-11-28
  • 3 回答
  • 0 關注
  • 677 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號