开发者

Enabling the button visibility for different accounts

I'm currently working on a website that requires me to enable validation for different accounts.

I have 2 accounts - Admin and User.

My Admin account is able to view all the functions available in the website, but the User is only allowed a few functions.

What I have in mind is to disable the visibility of a button - btnUpload.

Below are the codes that I've came up with so far.

       Mp.Mp login = new Mp.Mp();
        bool result = login.AuthenticateUser(tbxUsername.Text, tbxPassword.Text); 
        if (result == 开发者_Python百科true)             {
            Session.Add("Session_name", tbxUsername.Text);
            //Session["Username"] = tbxUsername.Text;
            Response.Redirect("Index.aspx");
        }

I need help with the visibility of buttons to ensure that btnUpload appears only to Admin and not User.


May be you want some thing like this

if(Session["Session_name"] == "admin")
 {
   btnUpload.Visible = true; 
 }
 else
 { 
   btnUpload.Visible = false; 
 }


You have RollName AND RollID For Identify your user by that roleid. You just need to check rollID at time of user login and store your user rollid in session and then check this rollid in whatever page where you need to check constrain regarding user role.


try

btnUpload.Visible = Session ["Session_name"] == "Admin";


How you are going to decide if the user is admin or a regular user? In simplistic scenario, your user data may have a flag that indicates whether user is an admin or not. Flexible approaches uses role based security - so if the user is member of particular role then he get access to certain features. So in such system, you can have a access right (or feature) for admin privileges and admin role will have this feature. In integrated authentication schemes, you can also use on windows groups or active directory groups as a security role. ASP.NET has good support for role based security (see this, this and this). Regardless of a implementation, once you decide is user is admin or not, controlling UI is very simple thing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜