I am new to asp.net I have to do a task which is to disable some controls for users if they dont have permission.in a page, if the user is basic user, then that user can view the data but the update and delete button should be disabled.but if the user has
got update privilege then the update button should be enabled. and if the user has both update and delete privilege then both update and delete button should be enabled.
rathinapriya
0 Points
1 Post
how to do this task?
May 10, 2012 02:48 PM|LINK
hi,
I am new to asp.net I have to do a task which is to disable some controls for users if they dont have permission.in a page, if the user is basic user, then that user can view the data but the update and delete button should be disabled.but if the user has got update privilege then the update button should be enabled. and if the user has both update and delete privilege then both update and delete button should be enabled.
how to do this task?
frez
Contributor
5418 Points
913 Posts
Re: how to do this task?
May 10, 2012 02:56 PM|LINK
Madhu1234
Participant
1380 Points
287 Posts
Re: how to do this task?
May 10, 2012 06:27 PM|LINK
Step 1:First assign roles(to your users like admin,member..) in Global.asax like below.
protected void Application_AuthenticateRequest(object sender, EventArgs e)
{
if (Request.IsAuthenticated)
{
string[] arRoles = new string[2];
switch (User.Identity.Name)
{
case "u1":
arRoles[0] = "r1"; arRoles[1] = "r4";
break;
case "u2":
arRoles[0] = "r2"; arRoles[1] = "r4";
break;
default:
arRoles[0] = "r3"; arRoles[1] = "r4";
break;
}
Context.User = new System.Security.Principal.GenericPrincipal(User.Identity, arRoles);
}
}
Step 2:Then based on ur requirement enable/disable the required buttons like below..
protected void Page_Load(object sender, EventArgs e)
{
btnUpdate.Visible = User.IsInRole("r2");
}
Hope this helps you ..