0

I had my code to check the current logged user , it is worked well on local host but when I deployed on server it doesn't work .

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[];  
    }
}
James
  • 80,725
  • 18
  • 167
  • 237
Egydeveloper
  • 195
  • 1
  • 4
  • 19
  • Which part doesn't work? – James Mar 25 '14 at 14:40
  • searcher.Filter = string.Format(CultureInfo.InvariantCulture, "(sAMAccountName={0})", Page.User.Identity.Name); – Egydeveloper Mar 25 '14 at 14:46
  • Probably don't have Windows authentication enabled for the site. Confirm it's Enabled within the site's dashboard under the authentication section. – Brad Christie Mar 25 '14 at 14:49
  • Also check that windows authentication is enabled in IIS for the website. look into: http://stackoverflow.com/questions/8067448/in-iis-why-doesnt-window-authentication-show-up-as-one-of-the-options-for-my-w – Alok Mar 25 '14 at 14:54
  • @Alok it is enabled but the code doesnot work – Egydeveloper Mar 25 '14 at 15:10
  • @Egydeveloper look into http://stackoverflow.com/questions/11952115/activedirectory-query-doesnt-work-from-server – Alok Mar 25 '14 at 15:42

0 Answers0