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

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

ASP.NET MVC 4使用權限代碼自定義授權屬性(無角色)

ASP.NET MVC 4使用權限代碼自定義授權屬性(無角色)

慕碼人8056858 2019-08-09 15:44:10
ASP.NET MVC 4使用權限代碼自定義授權屬性(無角色)我需要在我的MVC 4應用程序中根據用戶權限級別(沒有角色,只分配給用戶的CRUD操作級別的權限級別)來控制對視圖的訪問。舉個例子; AuthorizeUser下面將是我的自定義屬性,我需要像這樣使用它:[AuthorizeUser(AccessLevels="Read Invoice, Update Invoice")]public ActionResult UpdateInvoice(int invoiceId){    // some code...    return View();}[AuthorizeUser(AccessLevels="Create Invoice")]public ActionResult CreateNewInvoice(){   // some code...   return View();}[AuthorizeUser(AccessLevels="Delete Invoice")]public ActionResult DeleteInvoice(int invoiceId){   // some code...   return View();}有可能這樣做嗎?
查看完整描述

3 回答

?
冉冉說

TA貢獻1877條經驗 獲得超1個贊

這是對prev的修改?;卮稹V饕獏^別在于用戶未經過身份驗證時,它使用原始的“HandleUnauthorizedRequest”方法重定向到登錄頁面:

   protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
    {

        if (filterContext.HttpContext.User.Identity.IsAuthenticated) {

            filterContext.Result = new RedirectToRouteResult(
                        new RouteValueDictionary(
                            new
                            {
                                controller = "Account",
                                action = "Unauthorised"
                            })
                        );
        }
        else
        {
             base.HandleUnauthorizedRequest(filterContext);
        }
    }


查看完整回答
反對 回復 2019-08-09
  • 3 回答
  • 0 關注
  • 673 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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