我正在使用 Asp.Net/C#
构建应用程序。我正在使用 Forms Authentication
。我有一个要求,我的许多 都经过身份验证( 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;
有没有更好的方法来完成这个。非常感谢任何帮助。谢谢
最佳答案
在这里您可以使用 Membesship User 类和 RolePrincipal将用户分开。
if(HttpContext.Current.User.IsInRole("Level1"))
{
FilesGrid.Columns[1].Visible = true;
}
else
{
FilesGrid.Columns[1].Visible = false;
}
因此,您为您的用户设置不同的成员(member)名称,然后根据成员(member)角色向他们展示不同的控件。
部分链接:
http://msdn.microsoft.com/en-us/library/ff648345.aspx
http://msdn.microsoft.com/en-us/library/system.web.security.roleprincipal.isinrole.aspx
关于c# - 将某些页面功能或用户界面限制为 Asp.Net 中经过身份验证的用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10186549/