请有人可以告诉我最好的方式让我向几个人显示一个按钮但不会向所有访问我的应用的人显示,这是我的代码:
var a = Context.User.Identity.Name.Split('\\');
var adEntry = new DirectoryEntry("WinNT://" + a[0] + "/" + a[1]);
var userName = adEntry.Properties["FullName"].Value.ToString();
LinkButton5.Visible = userName == "name 1";
//LinkButton5.Visible = userName == "name 2";
//LinkButton5.Visible = userName == "name 3";
//LinkButton5.Visible = userName == "name 4";
你可以看到我是否只允许一个名字如何允许其他人
答案 0 :(得分:2)
我实际上做过这样的事情:
// Create hash list to hold allowed users
HashSet<string> allowed_users = new HashSet<string>();
// Add users here
// Get current user
var entry = new DirectoryEntry("WinNT://" + a[0] + "/" + a[1]);
var username = entry.Properties["FullName"].Value.ToString();
// Toggle link button
LinkButton.Visible = allowed_users.Contains(username);