c# 4.0 - Active Directory throwing Exception, on hosting the application in IIS but working fine from Visual Studio. Please suggest how to resolve this? -


i developing intranet web-application. requirement build application using single sign on(sso). implemented windows authentication & fetching user details active directory passing user domain & userid of user received after windows authentication.

getting userid & domain after windows authentication

void session_start(object sender, eventargs e)     {         logger logger = new logger();         logger.logmessage("creating session user- "; + user.identity.name);         sessionmanager.createusersession(user.identity.name);       } 

in create user session method below calling getuserdetails method in authentication manager class

public class sessionmanager {     public static void createusersession(string clientwindowsid)     {         logger logger = new logger();         userprofile user = new userprofile();         authenticationservice authenticationmanager = new authenticationservice();         string userid = clientwindowsid.contains("\\") ? clientwindowsid.split(new string[] { "\\" }, stringsplitoptions.none)[1] : clientwindowsid;         string domain = clientwindowsid.contains("\\") ? clientwindowsid.split(new string[] { "\\" }, stringsplitoptions.none)[0] : "ins";         logger.logmessage("user id: " + userid);         logger.logmessage("domain: " + domain);         user = authenticationmanager.getuserdetails(domain, userid);         httpcontext.current.session.add("userapplicationrole", user.userapplicationrole);         httpcontext.current.session.add("firstname", user.firstname);         httpcontext.current.session.add("lastname", user.lastname);         httpcontext.current.session.add("middlename", user.middlename);         httpcontext.current.session.add("displayname", user.userdisplayname);                 } 

}

the below method in authentication manager calls activedirectory user details

public userprofile getuserdetails(string domain, string userid)     {         var user = new userprofile();         logger logger = new logger();          try         {              using (hostingenvironment.impersonate())             {                  //find users domain                 principalcontext ad = new principalcontext(contexttype.domain, domain);                 userprincipal u = new userprincipal(ad);                 u.samaccountname = userid; //for finding particular user                 principalsearcher search = new principalsearcher(u);                  foreach (userprincipal result in search.findall())                 {                      if (result != null)                     {                          directoryentry de = result.getunderlyingobject() directoryentry;                         if (de.properties["samaccountname"].value.tostring() == userid)                         {                              user.firstname = de.properties["givenname"].value.tostring();                             user.lastname = de.properties["sn"].value.tostring();                             user.functionalrole = de.properties["role"].value != null ? de.properties["role"].value.tostring() : string.empty;                             user.email = de.properties["mail"].value.tostring();                             user.samaccountname = de.properties["samaccountname"].value.tostring();                             user.userprincipalname = de.properties["userprincipalname"].value.tostring();                             user.userdisplayname = de.properties["displayname"].value.tostring();                         }                     }                 }             }             user.userapplicationrole = getmappedapplicationrole(user.functionalrole);          }         catch (exception ex)         {             logger.logexception(ex, ex.innerexception);             console.write(ex.message);             throw;          }          return user;      } 

every thing working fine when running application visual studio, when deploying code in iis, application not able find out user details active directory. it's throwing below exception getuserdetails method of authentication manager class. system.runtime.interopservices.comexception (0x8007052e): logon failure: unknown user name or bad password.

please suggest how issue can solved. in advance.


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -