views:

25

answers:

1

Hello, i have to build a ASPNET website on which some functionalities will be available to logged in users. I'm trying to understand the right thing to to in building my pages.

I've found the following code in Page_PreInit:

protected void Page_PreInit(object sender, EventArgs e) 
{ 

if (Membership.GetUser() == null) //check the user.. Weather user is logged in or not
{
  this.Page.MasterPageFile = "~/General.master";

}
if (Membership.GetUser() == "ADMIN") //check the ADMIN.. Weather ADMIN is logged in or not
{
  this.Page.MasterPageFile = "~/ADMIN.master";
}
else
{
  this.Page.MasterPageFile = "~/Member.master";
}
}

..but i don't' know if this is the right approach in designing an app.

Is it right to switch at runtime Master page according to username/role?

Can you give me some suggestions?

Thanks in advance ! c.

+1  A: 

You wouldn't normally change the whole master page for this sort of thing unless you really need the entire layout to be different.

For simpler scenarios, you probably want to use the LoginView control. Have a read of this:

http://asp.dotnetheaven.com/aspnet/doc/ctrlref/login/loginview.aspx

elkdanger