954,518 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

User-Based Authorization (C#)

Hi,

I have three roles engineer,supuvisor and manager for my website

and I have three master pages engineer.master , supervisor.master and mgr.master
and i have some specific aspx pages for engineer,supervisor and manager.

I want to use engineer.master page for an aspx page if engineer user is logged in and want to use supervisor.master page if supervisor logged in ans so on for the manager.
How can I achieve this?

Thanks in advance!!!

Im getting error

here is the code :
protected override void OnPreInit(EventArgs e) {
base.OnPreInit(e);
switch (Session["role"].ToString())
{
case "1":
MasterPageFile = "ME.Master";
break;
case "2":
MasterPageFile= "Supervisor.Master";
break;
case "3":
MasterPageFile = "Manager.Master";
break;

default:
MasterPageFile = "default.Master";
break;
}

Thank you

uva1102
Light Poster
40 posts since Aug 2011
Reputation Points: 10
Solved Threads: 0
 

Hi,

I have three roles engineer,supuvisor and manager for my website

and I have three master pages engineer.master , supervisor.master and mgr.master
and i have some specific aspx pages for engineer,supervisor and manager.

i want, if supervisor(user) log on and will direct to supervisor.master page
same goes to Engineer.. and Manager.
3 roles have different master page(coz 3 of them have different content)
How can I achieve this?

Thanks in advance!!!

uva1102
Light Poster
40 posts since Aug 2011
Reputation Points: 10
Solved Threads: 0
 

If your're storing the user details in arrays you can add an int field to the array called somethin like AuthLevel and use 1, 2 or 3 as the different roles. One logging in you would do a check to see if the user exists and depending on the value of that user's AuthLevel field.

If your using an connected database it would be easier, especially if your going to be storing data entered into the different forms.

Hope this helps

ChrisHunter
Posting Whiz in Training
276 posts since Feb 2011
Reputation Points: 36
Solved Threads: 28
 

Sorry i dont get you.

public partial class ME0 : System.Web.UI.Page {
sqlDataContext sdc = new sqlDataContext();

protected override void OnPreInit(EventArgs e) {
base.OnPreInit(e);
employee emp = Cache["emp"] as employee;


switch (Session["role"].ToString() )
{

case "1":
MasterPageFile = "Engineer.Master";
break;
case "2":
MasterPageFile= "Supervisor.Master";
break;
case "3":
MasterPageFile = "DOD.Master";
break;
default:
MasterPageFile = "Manager.Master";
break;
}

uva1102
Light Poster
40 posts since Aug 2011
Reputation Points: 10
Solved Threads: 0
 

i was suggesting a solution that uses arrays to store user details but if you're using a a database that will be easier.

If i understand you correctly you want a different form to be loaded depending on the type of user that logs in (engineer, supervisor, manager). Simply add a column to the user table to store the different types of user and then during the check to see if the user exists simply check whether they are a manager, supervisor or engineer and load the appropriate form.

ChrisHunter
Posting Whiz in Training
276 posts since Feb 2011
Reputation Points: 36
Solved Threads: 28
 
MikeyIsMe
Junior Poster
142 posts since Nov 2010
Reputation Points: 32
Solved Threads: 15
 

Yes Im using database..

uva1102
Light Poster
40 posts since Aug 2011
Reputation Points: 10
Solved Threads: 0
 

this is the error im getting...Exception Details: System.Web.HttpException: The file '/Manager.Master' does not exist.

uva1102
Light Poster
40 posts since Aug 2011
Reputation Points: 10
Solved Threads: 0
 

found the solutions..thanks everyone.

uva1102
Light Poster
40 posts since Aug 2011
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: