Dynamically change master page at runtime based on UserRole

Posted by Jayeshl under C# category on | Points: 40 | Views : 2735
In real life example when there are multiple users for same system and all have their role and responsibility at that time need to call same page for all user with their respective role with different functionaly on masterpage.

user can access their different masterpage at runtime.

here is code sample example in which there are three different users.

1. Admin
2. Employee
3. Client

and all have same ChangePassword page.. with their respective functionality in master page.

protected void Page_PreInit(object sender, EventArgs e)
int iRole = 0;
int.TryParse(Session["Role"].ToString(),out iRole);
if (iRole == 1){
this.MasterPageFile = "AdminMaster.master";
if (iRole == 2){
this.MasterPageFile = "EmployeeMaster.master";
if (iRole == 3){
this.MasterPageFile = "ClientMaster.master";

this code should be in content page Page_PreInit method.

Jayesh L

Comments or Responses

Login to post response