如何使用成员资格构建 ASP.NET 网站
我必须构建一个 ASP.NET
网站,登录用户可以在该网站上使用某些功能。我正在尝试了解构建页面的正确方法。
我在 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";
}
}
但我不知道这是否是设计应用程序的正确方法。
根据用户名/角色在运行时切换母版页是否正确?
你能给我一些建议吗?
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") //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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通常,您不会为此类事情更改整个母版页,除非您确实需要整个布局不同。
对于更简单的场景,您可能需要使用 LoginView 控件。阅读以下内容:
http://asp.dotnetheaven.com/aspnet /doc/ctrlref/login/loginview.aspx
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