实现基于自定义视图的授权asp.net核心

时间:2019-07-11 08:39:31

标签: c# asp.net-mvc asp.net-core roles

我有一个基于自定义登录cookie的系统,它不使用asp.net核心框架中的内置用户管理器。如何创建基于视图的授权  在ASP.NET Core中是否有类似于System.Web.UI.Control的东西?

protected override void OnLoadComplete(EventArgs e)
{
    if (Role == 0)
        Response.Redirect(System.Configuration.ConfigurationManager.AppSettings["unauthorized"]);
    System.Data.Common.DbDataReader dr = Yetki.PageControlsbyUser(pageUrl, ProjeKod, Role);
    try
    {
        while (dr.Read())
        {
            foreach (System.Web.UI.Control cList in Page.Controls)
            {
                System.Web.UI.Control ctrl = FindRecursive(cList, dr["ControlAd"].ToString());
                if (ctrl != null)
                {
                    int dRole = Convert.ToInt32(dr["roleId"]);

                    switch (role)
                    {
                        case 1:
                            ctrl.Visible = false;
                            break;
                        case 2:
                            if (!(dRole > 2)) { ctrl.Visible = true; } else ctrl.Visible = false;
                            break;
                        case 3:
                            ctrl.Visible = true;
                            break;
                    }
                }
            }
        }
    }
    finally { dr.Close(); }
    base.OnInitComplete(e);
}

我正在考虑创建一个界面,以检查是否有足够的用户要注入视图中,但是我不确定这是否是有效的解决方案

0 个答案:

没有答案