sql - setting form authentication in impersonate -


i have intranet website. database uses windows authentication. website uses network credential using logonuser().

intptr token = intptr.zero;          bool result = logonuser(txtusername.text, txtdomain.text, txtpassword.text, 2, 0, ref token); //2, 0, ref token);         if (result)         {             windowsidentity newid = new windowsidentity(token);             windowsimpersonationcontext impersonateduser = newid.impersonate();             formsauthentication.setauthcookie(txtdomain.text + "\\" + txtusername.text, false);             using (sqlconnection cnn=new sqlconnection(configurationmanager.connectionstrings["connectionstring"].connectionstring))             {                 using (sqlcommand cmd=new sqlcommand("select * [user] username=@user", cnn))                 {                     cmd.parameters.clear();                     cmd.parameters.addwithvalue("@user",txtdomain.text+"\\"+txtusername.text);                      cnn.open();                     sqldatareader rdr=cmd.executereader();                     rdr.read();                     if(rdr.hasrows)                     {                            cnn.close();                         lblnotification.text = system.security.principal.windowsidentity.getcurrent().name;                         session.add("principal", new windowsprincipal(newid));                     }                     else                     {                         lblnotification.text="username or password invalid";                     }                 }             } 

the code executes including sql when goes next page (home.aspx) error:

error message

the error encountered in windows authentication in sql. 'ecp' domain , 'phappcvtl002198$' computer name not expecting that. expecting username entered in login form.


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -