ASP.NET userid and password using Active Directory problem -


i have developed application checks entered userid , password against active directory ..its working fine on development when put on iis uat machine authentication throwing error "runtime error" ...

here code behind

  protected void loginbutton_click(object sender, eventargs e)     {          if (authenticateuser("mydomain", txtusername.text, txtpassword.text))          {              //fetch role             database db = databasefactory.createdatabase();              //create command object             dbcommand cmd = db.getstoredproccommand("sp_rolesforuser");             db.addinparameter(cmd, "@uid", system.data.dbtype.string, 15);             db.setparametervalue(cmd, "@uid", txtusername.text);             system.data.idatareader reader = db.executereader(cmd);             system.collections.arraylist rolelist = new system.collections.arraylist();             if (reader.read())             {                 rolelist.add(reader[0]);                 string myroles = (string)rolelist[0];                 //read user name                 string uname = (string)reader[1];                 //read user menu id                 int menuid = convert.toint16(reader[2]);                 //lbl_error.text = "user ready redirect @ main page...";                  formsauthenticationticket ticket = new formsauthenticationticket(1, txtusername.text, datetime.now,                 datetime.now.addminutes(30), true, myroles, formsauthentication.formscookiepath);                  //read user full name in session variable shared across whole application                 session["uid"] = txtusername.text;                 session["ufullname"] = uname; //myname; //uname;                 session["branch"] = 1;                  //for security reasons may hash cookies                 string hashcookies = formsauthentication.encrypt(ticket);                 httpcookie cookie = new httpcookie(formsauthentication.formscookiename, hashcookies);                  // add cookie user browser                 response.cookies.add(cookie);                  //constructing menu according user role                 string x = buildmenu(menuid);                  global.menustring = null;                 global.menustring = x;                  string returnurl = "~/main.aspx";                  if (request.querystring["rurl"] != null)                     response.redirect(request.querystring["rurl"]);                 else                     response.redirect(returnurl);             }             else             {                 //validation error here...                 validateoverlay("throwerror", "throwerror()");                 return;             }         }     }            public bool authenticateuser(string domain, string username, string password)     {         string domainandusername = domain + @"\" + username;         directoryentry entry = new directoryentry("ldap://mydomain.com", domainandusername, password);         try         {             object obj = entry.nativeobject;             directorysearcher search = new directorysearcher(entry);             search.filter = "(samaccountname=" + username + ")";             search.propertiestoload.add("cn");             searchresult result = search.findone();             myname = result.getdirectoryentry().name.replace("cn=", "");              if (result == null)             {                 return false;             }         }         catch (exception ex)         {             return false;         }         return true;     } 

here web.config

<?xml version="1.0"?> <!--  note: alternative hand editing file can use  web admin tool configure settings application. use website->asp.net configuration option in visual studio. full list of settings , comments can found in  machine.config.comments located in  \windows\microsoft.net\framework\v2.x\config   -->  <configuration> <configsections>     <section name="dataconfiguration" type="microsoft.practices.enterpriselibrary.data.configuration.databasesettings, microsoft.practices.enterpriselibrary.data, version=4.1.0.0, culture=neutral, publickeytoken=31bf3856ad364e35"/>     <sectiongroup name="system.web.extensions" type="system.web.configuration.systemwebextensionssectiongroup, system.web.extensions, version=3.5.0.0, culture=neutral, publickeytoken=31bf3856ad364e35">         <sectiongroup name="scripting" type="system.web.configuration.scriptingsectiongroup, system.web.extensions, version=3.5.0.0, culture=neutral, publickeytoken=31bf3856ad364e35">             <section name="scriptresourcehandler" type="system.web.configuration.scriptingscriptresourcehandlersection, system.web.extensions, version=3.5.0.0, culture=neutral, publickeytoken=31bf3856ad364e35" requirepermission="false" allowdefinition="machinetoapplication"/>             <sectiongroup name="webservices" type="system.web.configuration.scriptingwebservicessectiongroup, system.web.extensions, version=3.5.0.0, culture=neutral, publickeytoken=31bf3856ad364e35">                 <section name="jsonserialization" type="system.web.configuration.scriptingjsonserializationsection, system.web.extensions, version=3.5.0.0, culture=neutral, publickeytoken=31bf3856ad364e35" requirepermission="false" allowdefinition="everywhere"/>                 <section name="profileservice" type="system.web.configuration.scriptingprofileservicesection, system.web.extensions, version=3.5.0.0, culture=neutral, publickeytoken=31bf3856ad364e35" requirepermission="false" allowdefinition="machinetoapplication"/>                 <section name="authenticationservice" type="system.web.configuration.scriptingauthenticationservicesection, system.web.extensions, version=3.5.0.0, culture=neutral, publickeytoken=31bf3856ad364e35" requirepermission="false" allowdefinition="machinetoapplication"/>                 <section name="roleservice" type="system.web.configuration.scriptingroleservicesection, system.web.extensions, version=3.5.0.0, culture=neutral, publickeytoken=31bf3856ad364e35" requirepermission="false" allowdefinition="machinetoapplication"/>             </sectiongroup>         </sectiongroup>     </sectiongroup> </configsections> <dataconfiguration defaultdatabase="sqle2k8"/> <connectionstrings>     <!--<add name="sqle2k8" connectionstring="data source=10.21.4.175\sqle2k8;initial catalog=ebpm;user id=sa;password=admin123" providername="system.data.sqlclient"/>-->     <add name="sqle2k8" connectionstring="data source=iho-l633\sqle2k8;initial catalog=ebpm;user id=sa;password=admin123" providername="system.data.sqlclient"/> </connectionstrings> <appsettings/> <system.web>     <sessionstate timeout="50"/>     <!--          set compilation debug="true" insert debugging          symbols compiled page. because          affects performance, set value true          during development.     -->     <compilation debug="true">         <assemblies>             <add assembly="system.core, version=3.5.0.0, culture=neutral, publickeytoken=b77a5c561934e089"/>             <add assembly="system.web.extensions, version=3.5.0.0, culture=neutral, publickeytoken=31bf3856ad364e35"/>             <add assembly="system.data.datasetextensions, version=3.5.0.0, culture=neutral, publickeytoken=b77a5c561934e089"/>             <add assembly="system.xml.linq, version=3.5.0.0, culture=neutral, publickeytoken=b77a5c561934e089"/>             <add assembly="system.design, version=2.0.0.0, culture=neutral, publickeytoken=b03f5f7f11d50a3a"/>             <add assembly="system.web.extensions.design, version=3.5.0.0, culture=neutral, publickeytoken=31bf3856ad364e35"/>             <add assembly="system.windows.forms, version=2.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089"/>             <add assembly="system.directoryservices, version=2.0.0.0, culture=neutral, publickeytoken=b03f5f7f11d50a3a"/></assemblies>     </compilation>     <!--         <authentication> section enables configuration          of security authentication mode used          asp.net identify incoming user.      -->     <authentication mode="forms">         <!--         <customerrors> section enables configuration          of if/when unhandled error occurs          during execution of request. specifically,          enables developers configure html error pages          displayed in place of error stack trace.      <customerrors mode="remoteonly" defaultredirect="genericerrorpage.htm">         <error statuscode="403" redirect="noaccess.htm" />         <error statuscode="404" redirect="filenotfound.htm" />     </customerrors>     -->     </authentication>     <pages>         <controls>             <add tagprefix="asp" namespace="system.web.ui" assembly="system.web.extensions, version=3.5.0.0, culture=neutral, publickeytoken=31bf3856ad364e35"/>             <add tagprefix="asp" namespace="system.web.ui.webcontrols" assembly="system.web.extensions, version=3.5.0.0, culture=neutral, publickeytoken=31bf3856ad364e35"/>         </controls>     </pages>     <httphandlers>         <remove verb="*" path="*.asmx"/>         <add verb="*" path="*.asmx" validate="false" type="system.web.script.services.scripthandlerfactory, system.web.extensions, version=3.5.0.0, culture=neutral, publickeytoken=31bf3856ad364e35"/>         <add verb="*" path="*_appservice.axd" validate="false" type="system.web.script.services.scripthandlerfactory, system.web.extensions, version=3.5.0.0, culture=neutral, publickeytoken=31bf3856ad364e35"/>         <add verb="get,head" path="scriptresource.axd" type="system.web.handlers.scriptresourcehandler, system.web.extensions, version=3.5.0.0, culture=neutral, publickeytoken=31bf3856ad364e35" validate="false"/>     </httphandlers>     <httpmodules>         <add name="scriptmodule" type="system.web.handlers.scriptmodule, system.web.extensions, version=3.5.0.0, culture=neutral, publickeytoken=31bf3856ad364e35"/>     </httpmodules> </system.web> <system.codedom>     <compilers>         <compiler language="c#;cs;csharp" extension=".cs" warninglevel="4" type="microsoft.csharp.csharpcodeprovider, system, version=2.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089">             <provideroption name="compilerversion" value="v3.5"/>             <provideroption name="warnaserror" value="false"/>         </compiler>         <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" warninglevel="4" type="microsoft.visualbasic.vbcodeprovider, system, version=2.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089">             <provideroption name="compilerversion" value="v3.5"/>             <provideroption name="optioninfer" value="true"/>             <provideroption name="warnaserror" value="false"/>         </compiler>     </compilers> </system.codedom> <!--      system.webserver section required running asp.net ajax under internet     information services 7.0.  not necessary previous version of iis. --> <system.webserver>     <validation validateintegratedmodeconfiguration="false"/>     <modules>         <remove name="scriptmodule"/>         <add name="scriptmodule" precondition="managedhandler" type="system.web.handlers.scriptmodule, system.web.extensions, version=3.5.0.0, culture=neutral, publickeytoken=31bf3856ad364e35"/>     </modules>     <handlers>         <remove name="webservicehandlerfactory-integrated"/>         <remove name="scripthandlerfactory"/>         <remove name="scripthandlerfactoryappservices"/>         <remove name="scriptresource"/>         <add name="scripthandlerfactory" verb="*" path="*.asmx" precondition="integratedmode" type="system.web.script.services.scripthandlerfactory, system.web.extensions, version=3.5.0.0, culture=neutral, publickeytoken=31bf3856ad364e35"/>         <add name="scripthandlerfactoryappservices" verb="*" path="*_appservice.axd" precondition="integratedmode" type="system.web.script.services.scripthandlerfactory, system.web.extensions, version=3.5.0.0, culture=neutral, publickeytoken=31bf3856ad364e35"/>         <add name="scriptresource" precondition="integratedmode" verb="get,head" path="scriptresource.axd" type="system.web.handlers.scriptresourcehandler, system.web.extensions, version=3.5.0.0, culture=neutral, publickeytoken=31bf3856ad364e35"/>     </handlers> </system.webserver> <runtime>     <assemblybinding appliesto="v2.0.50727" xmlns="urn:schemas-microsoft-com:asm.v1"><dependentassembly>             <assemblyidentity name="system.web.extensions" publickeytoken="31bf3856ad364e35"/>             <bindingredirect oldversion="1.0.0.0-1.1.0.0" newversion="3.5.0.0"/>         </dependentassembly>         <dependentassembly>             <assemblyidentity name="system.web.extensions.design" publickeytoken="31bf3856ad364e35"/>             <bindingredirect oldversion="1.0.0.0-1.1.0.0" newversion="3.5.0.0"/>         </dependentassembly>     </assemblybinding></runtime> 

what doing wrong


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -