V
VSK
Hi all,
In our ASP.NET web application we have to enable or disable features in each
ASP.NET page based on role assigned to user.
Ex: if user who logs in is superisor then he can change phonenumber in
page1.aspx
if user who logs in is finaceofficial then he can just view the phone
number in page1.aspx
Thus Each page has elements whose functionality is enabled or disabled based
on roles.
Iam trying to do this checks in a Single class for all page and am not sure
whether it efficient.
My idea is to put code which checks the roles and enables and disabes server
controls in one class for easier maintenence.Not sure as to whether there is
any other alternative.
PS: am passing the entire Page object to the class :
objPageController.DeterminePageElements(this,"webform1");
Ex
a.aspx.cs
----------
private void Page_Load(object sender, System.EventArgs e)
{
PageController objPageController = new PageController();
objPageController.DeterminePageElements(this,"webform1");
}
PageController.cs
-----------------
public void DeterminePageElements(System.Web.UI.Page objPage,string
strPageName)
{
switch(strPageName){
case "webform1" :
//find the controls which are to be enabled or
//disabled from page collection.
//check for the role and credentials
//dummy code will be something like below
TextBox tb = objPage.FindControl("TextBox1");
if(security related checks)
{
tb1.Enabled = true;
}
else
{
}
case "" :
case "" :
....
}
}
Please let me know whether am doing anything wrong.
TIA for your patience
VSK
In our ASP.NET web application we have to enable or disable features in each
ASP.NET page based on role assigned to user.
Ex: if user who logs in is superisor then he can change phonenumber in
page1.aspx
if user who logs in is finaceofficial then he can just view the phone
number in page1.aspx
Thus Each page has elements whose functionality is enabled or disabled based
on roles.
Iam trying to do this checks in a Single class for all page and am not sure
whether it efficient.
My idea is to put code which checks the roles and enables and disabes server
controls in one class for easier maintenence.Not sure as to whether there is
any other alternative.
PS: am passing the entire Page object to the class :
objPageController.DeterminePageElements(this,"webform1");
Ex
a.aspx.cs
----------
private void Page_Load(object sender, System.EventArgs e)
{
PageController objPageController = new PageController();
objPageController.DeterminePageElements(this,"webform1");
}
PageController.cs
-----------------
public void DeterminePageElements(System.Web.UI.Page objPage,string
strPageName)
{
switch(strPageName){
case "webform1" :
//find the controls which are to be enabled or
//disabled from page collection.
//check for the role and credentials
//dummy code will be something like below
TextBox tb = objPage.FindControl("TextBox1");
if(security related checks)
{
tb1.Enabled = true;
}
else
{
}
case "" :
case "" :
....
}
}
Please let me know whether am doing anything wrong.
TIA for your patience
VSK