How to structure an ASP.NET website using membership
I have to build an ASP.NET
website on which some functionalities will be available to logged-in users. I'm trying to understand the right thing 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") //ch开发者_如何学运维eck 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?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
精彩评论