日韩在线中文字幕精品观看,国产精品天天爽夜夜爽,亚洲欧美成人一二三区官网,国产精品久久久久精品一,男人天堂网视频在线播放,c0930人妻斩り43r,99热国产精品视频在线,最新日本视频在线观看地址,日韩在线免费电影中文字幕

400-800-9385
網(wǎng)站建設(shè)資訊詳細

ASP.NET MVC3如何實現(xiàn)自定義權(quán)限系統(tǒng)判定和實現(xiàn)

發(fā)表日期:2013-09-21 00:00:00   作者來源:方維網(wǎng)絡(luò)   瀏覽:6518   標簽:ASP.NET    MVC3    

    ASP.NET本身擁有membership角色權(quán)限系統(tǒng),但是這個自帶的系統(tǒng)不夠靈活和強大,有時候操作起來比較繁瑣,這里方維網(wǎng)絡(luò)介紹一種如何根據(jù)控制器和方法自動判定權(quán)限,簡單方便。

    首先是定義一個類繼承ActionFilterAttribute類,然后重新方法OnActionExecuting  編寫如下代碼

    public override void OnActionExecuting(ActionExecutingContext filterContext)

        {
            if (!filterContext.HttpContext.User.Identity.IsAuthenticated)
            {
                //沒有登錄執(zhí)行的操作
            }
            else
            {
   
                //判斷是否存在角色
                FormsIdentity user = (FormsIdentity)HttpContext.Current.User.Identity;
 
                var au = db.AdminUser.Where(a => a.username == user.Name).ToList();
                if (au.Count > 0)
                {
                    // string purview= au[0].group.purview;
                    bool is_authorize = true;
                    string error_msg = "沒有權(quán)限訪問!";
                    string model = filterContext.RouteData.Values["controller"].ToString();
                    string action = filterContext.RouteData.Values["action"].ToString();
 
                    BLLAdminUser admin_user = new BLLAdminUser();
                    string purview=admin_user.getCheckPurview(model, action);//判斷權(quán)限
                    string mypurview = admin_user.getMyPurview();
                    is_authorize=admin_user.inPurview(purview, mypurview);
                    if (!is_authorize)
                    {
                         //如果驗證不通過執(zhí)行的方法
                    }
 
                }
 
            }
          
        }


    然后在控制器或方法前面加上[Authorize]驗證標記就行了。

如沒特殊注明,文章均為方維網(wǎng)絡(luò)原創(chuàng),轉(zhuǎn)載請注明來自http://www.nnjcqh.com/news/1993.html
相關(guān)網(wǎng)站設(shè)計案例