繁体   English   中英

ASP.NET模拟设计

[英]ASP.NET Impersonation design

这是我的ASP.NET身份验证操作。

    private void LoginButton_Click(Object sender,
                       EventArgs e)
    {
        string userName = txtUserName.Value;
        string password = txtUserPass.Value;

        if (ValidateUser(txtUserName.Value, txtUserPass.Value))
        {
            FormsAuthenticationTicket tkt;
            string cookiestr;
            HttpCookie ck;
            tkt = new FormsAuthenticationTicket(1, txtUserName.Value, DateTime.Now,
                                                DateTime.Now.AddMinutes(3), chkPersistCookie.Checked,
                                                userName + "@ticket");
            cookiestr = FormsAuthentication.Encrypt(tkt);
            ck = new HttpCookie(FormsAuthentication.FormsCookieName, cookiestr);
            if (chkPersistCookie.Checked)
                ck.Expires = tkt.Expiration;
            ck.Path = FormsAuthentication.FormsCookiePath;
            Response.Cookies.Add(ck);

            string strRedirect;
            strRedirect = Request["ReturnUrl"];
            if (strRedirect == null)
                strRedirect = "MyAccount.aspx";
            Response.Redirect(strRedirect, true);
        }
        else
            Response.Redirect("logon.aspx", true);

    }

我的数据库中有User表,其中保存了所有凭据。 使用ValidateUser方法我正在进行凭据验证。 我还有三种类型的用户:会员,主持人和管理员。 每种类型的成员都具有独特的功能。 假设我在我的数据库中存储了A,B和C T-SQL。

我该怎么做才能:

成员仅执行查询。

主持人执行A和B.

管理员执行A,B和C.

当然,我可以从Web应用程序管理执行,但我不确定它是多么安全。 从技术上讲,我可以在App之外执行类似的查询,它可以访问所有数据库数据。 我想以某种方式结合Web App登录和Db访问。

谢谢!

如果这些查询将来自Web应用程序,我认为您需要管理调用过程的代码端..您可以在数据库中维护URL列表,分配角色,并赋予这些角色访问特定URL的权限。 这些网址将决定用户可以执行哪些查询...

然后在您的代码中,您可以分配自定义属性来限制对它们的访问....

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM