我有我的代码来检查当前登录的用户,它在本地主机上运行良好但是当我部署在服务器上时它不起作用。
private void checkUser()
{
DirectorySearcher searcher = new DirectorySearcher();
searcher.SearchScope = SearchScope.Subtree;
searcher.Filter = string.Format(CultureInfo.InvariantCulture, "(sAMAccountName={0})", Page.User.Identity.Name);
SearchResult findUser = searcher.FindOne();
if (findUser != null)
{
DirectoryEntry user = findUser.GetDirectoryEntry();
string Mobile = user.Properties["Mobile"].Value.ToString();
string Login = user.Properties["sAMAccountName"].Value.ToString();
if (user.Properties["Department"].Value != null)
LoggedDepartement = user.Properties["Department"].Value.ToString();
string title = user.Properties["title"].Value.ToString();
data = user.Properties["thumbnailPhoto"].Value as byte[];
}
}