ASP.NET userid and password using Active Directory problem
<p>I have developed an application which checks the entered userid and password against the active directory ..its working fine on development but when i put it on IIS UAT machine the authentication is throwing error "Runtime Error" ...</p>

<h2>here is my code behind</h2>

<pre><code>  protected void LoginButton_Click(object sender, EventArgs e)
    {

        if (AuthenticateUser("MYDOMAIN", txtUsername.Text, txtPassword.Text))
         {

            //Fetch the 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 to redirect at 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 which will be shared across the whole application
                Session["uid"] = txtUsername.Text;
                Session["ufullname"] = uname; //myname; //uname;
                Session["branch"] = 1;

                //For security reasons we may hash the cookies
                string hashCookies = FormsAuthentication.Encrypt(ticket);
                HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hashCookies);

                // add the cookie to user browser
                Response.Cookies.Add(cookie);

                //Constructing Menu according to 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;
    }
</code></pre>

<p>here is the web.config</p>

<pre><code>&lt;?xml version="1.0"?&gt;
&lt;!-- 
Note: As an alternative to hand editing this file you can use the 
web admin tool to configure settings for your application. Use
the Website-&gt;Asp.Net Configuration option in Visual Studio.
A full list of settings and comments can be found in 
machine.config.comments usually located in 
\Windows\Microsoft.Net\Framework\v2.x\Config 
 --&gt;
 &lt;configuration&gt;
&lt;configSections&gt;
    &lt;section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/&gt;
    &lt;sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"&gt;
        &lt;sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"&gt;
            &lt;section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/&gt;
            &lt;sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"&gt;
                &lt;section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere"/&gt;
                &lt;section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/&gt;
                &lt;section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/&gt;
                &lt;section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/&gt;
            &lt;/sectionGroup&gt;
        &lt;/sectionGroup&gt;
    &lt;/sectionGroup&gt;
&lt;/configSections&gt;
&lt;dataConfiguration defaultDatabase="SQLE2K8"/&gt;
&lt;connectionStrings&gt;
    &lt;!--&lt;add name="SQLE2K8" connectionString="Data Source=10.21.4.175\SQLE2K8;Initial Catalog=EBPM;User ID=sa;Password=admin123" providerName="System.Data.SqlClient"/&gt;--&gt;
    &lt;add name="SQLE2K8" connectionString="Data Source=IHO-L633\SQLE2K8;Initial Catalog=EBPM;User ID=sa;Password=admin123" providerName="System.Data.SqlClient"/&gt;
&lt;/connectionStrings&gt;
&lt;appSettings/&gt;
&lt;system.web&gt;
    &lt;sessionState timeout="50"/&gt;
    &lt;!-- 
        Set compilation debug="true" to insert debugging 
        symbols into the compiled page. Because this 
        affects performance, set this value to true only 
        during development.
    --&gt;
    &lt;compilation debug="true"&gt;
        &lt;assemblies&gt;
            &lt;add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/&gt;
            &lt;add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/&gt;
            &lt;add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/&gt;
            &lt;add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/&gt;
            &lt;add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/&gt;
            &lt;add assembly="System.Web.Extensions.Design, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/&gt;
            &lt;add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/&gt;
            &lt;add assembly="System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/&gt;&lt;/assemblies&gt;
    &lt;/compilation&gt;
    &lt;!--
        The &lt;authentication&gt; section enables configuration 
        of the security authentication mode used by 
        ASP.NET to identify an incoming user. 
    --&gt;
    &lt;authentication mode="Forms"&gt;
        &lt;!--
        The &lt;customErrors&gt; section enables configuration 
        of what to do if/when an unhandled error occurs 
        during the execution of a request. Specifically, 
        it enables developers to configure html error pages 
        to be displayed in place of a error stack trace.

    &lt;customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm"&gt;
        &lt;error statusCode="403" redirect="NoAccess.htm" /&gt;
        &lt;error statusCode="404" redirect="FileNotFound.htm" /&gt;
    &lt;/customErrors&gt;
    --&gt;
    &lt;/authentication&gt;
    &lt;pages&gt;
        &lt;controls&gt;
            &lt;add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/&gt;
            &lt;add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/&gt;
        &lt;/controls&gt;
    &lt;/pages&gt;
    &lt;httpHandlers&gt;
        &lt;remove verb="*" path="*.asmx"/&gt;
        &lt;add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/&gt;
        &lt;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"/&gt;
        &lt;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"/&gt;
    &lt;/httpHandlers&gt;
    &lt;httpModules&gt;
        &lt;add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/&gt;
    &lt;/httpModules&gt;
&lt;/system.web&gt;
&lt;system.codedom&gt;
    &lt;compilers&gt;
        &lt;compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"&gt;
            &lt;providerOption name="CompilerVersion" value="v3.5"/&gt;
            &lt;providerOption name="WarnAsError" value="false"/&gt;
        &lt;/compiler&gt;
        &lt;compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" warningLevel="4" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"&gt;
            &lt;providerOption name="CompilerVersion" value="v3.5"/&gt;
            &lt;providerOption name="OptionInfer" value="true"/&gt;
            &lt;providerOption name="WarnAsError" value="false"/&gt;
        &lt;/compiler&gt;
    &lt;/compilers&gt;
&lt;/system.codedom&gt;
&lt;!-- 
    The system.webServer section is required for running ASP.NET AJAX under Internet
    Information Services 7.0.  It is not necessary for previous version of IIS.
--&gt;
&lt;system.webServer&gt;
    &lt;validation validateIntegratedModeConfiguration="false"/&gt;
    &lt;modules&gt;
        &lt;remove name="ScriptModule"/&gt;
        &lt;add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/&gt;
    &lt;/modules&gt;
    &lt;handlers&gt;
        &lt;remove name="WebServiceHandlerFactory-Integrated"/&gt;
        &lt;remove name="ScriptHandlerFactory"/&gt;
        &lt;remove name="ScriptHandlerFactoryAppServices"/&gt;
        &lt;remove name="ScriptResource"/&gt;
        &lt;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"/&gt;
        &lt;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"/&gt;
        &lt;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"/&gt;
    &lt;/handlers&gt;
&lt;/system.webServer&gt;
&lt;runtime&gt;
    &lt;assemblyBinding appliesTo="v2.0.50727" xmlns="urn:schemas-microsoft-com:asm.v1"&gt;&lt;dependentAssembly&gt;
            &lt;assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35"/&gt;
            &lt;bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
            &lt;assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35"/&gt;
            &lt;bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/&gt;
        &lt;/dependentAssembly&gt;
    &lt;/assemblyBinding&gt;&lt;/runtime&gt;
</code></pre>

<p></p>

<p>What am i doing wrong</p>
