[英]Restricting certain page functionality or user interface to authenticated users in Asp.Net
我正在使用Asp.Net/C#
来构建应用程序。我正在使用Forms Authentication
。我有一个要求,使许多经过authenticated (not anonymous) users
只能使用某些页面功能或用户界面。我猜Login Control
可以只能用于经过Authenticated vs Anonymous
所以我的问题是,当我知道要从特定的经过身份验证的用户中隐藏某些页面组件时,该如何处理。您认为我需要在page_load事件中使用它来隐藏吗具有此类要求的页面的组件。
// Is this Tito visiting the page?
string userName = User.Identity.Name;
if (string.Compare(userName, "Tito", true) == 0)
// This is Tito, SHOW the Delete column
FilesGrid.Columns[1].Visible = true;
else
// This is NOT Tito, HIDE the Delete column
FilesGrid.Columns[1].Visible = false;
是否有更好的方法来完成此任务。非常感谢任何帮助。
在这里,您可以使用Membeship User类和RolePrincipal来分隔用户。
if(HttpContext.Current.User.IsInRole("Level1"))
{
FilesGrid.Columns[1].Visible = true;
}
else
{
FilesGrid.Columns[1].Visible = false;
}
因此,您以不同的成员资格名称创建和放置用户,然后向他们显示取决于成员角色的不同控件。
一些链接:
http://msdn.microsoft.com/en-us/library/ff648345.aspx
http://msdn.microsoft.com/zh-CN/library/system.web.security.roleprincipal.isinrole.aspx
您还需要知道,当您仅隐藏控件时,它的base64编码值仍然存在于viewstate中。 客户端能够读取它。
客户端还可以读取哪个隐藏控件触发动作。 没有任何事情可以阻止“智能”客户端触发此操作。
因此:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.