title: AD Authentication Unknown username or bad password
body: <p>I am using VS2005 C#.</p>
  
  <p>I am trying to switch my login authentication from the ASP.NET Web Site Administration Tool from using <em>Internet</em> to <em>Local Network</em>, which is the Windows authentication.</p>
  
  <p>I have set the MembershipProvider of my Login tool in my web form to my MP name, <em>MyADMembershipProvider</em>.</p>
  
  <p>Below is my current <em>web.config</em> file after making some changes:</p>
  
  <pre><code>&lt;configuration&gt;
      &lt;appSettings/&gt;
      &lt;connectionStrings&gt;
          &lt;add name="SODConnectionString" connectionString="CONNECTIONSTRING" providerName="System.Data.SqlClient"/&gt;
  
          &lt;add name="ADConnectionString" connectionString="LDAP://URL"/&gt;
      &lt;/connectionStrings&gt;
      &lt;system.web&gt;
          &lt;authentication mode="Windows" /&gt;
      &lt;roleManager enabled="true" /&gt;
      &lt;pages styleSheetTheme="DataWebControls"/&gt;
          &lt;membership defaultProvider="MyADMembershipProvider"&gt;
              &lt;providers&gt;
                  &lt;clear/&gt;
                  &lt;add name="MyADMembershipProvider" type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=PUBTOKEN" applicationName="SOD" connectionStringName="ADConnectionString" connectionUsername="domain\Username" connectionPassword="Password" attributeMapUsername="sAMAccountName" enableSearchMethods="true" /&gt;
              &lt;/providers&gt;
  
          &lt;/membership&gt;
          &lt;siteMap defaultProvider="XmlSiteMapProvider" enabled="true"&gt;
              &lt;providers&gt;
                  &lt;add name="XmlSiteMapProvider"
        description="Default SiteMap provider."
        type="System.Web.XmlSiteMapProvider"
        siteMapFile="Web.sitemap"
        securityTrimmingEnabled="true" /&gt;
              &lt;/providers&gt;
          &lt;/siteMap&gt;
              &lt;compilation debug="true"/&gt;
              &lt;!-- Turn on Custom Errors --&gt;
          &lt;customErrors defaultRedirect="~/Error/NetworkError.aspx" mode="On"&gt;
     &lt;error statusCode="404" redirect="~/Error/PageNotFound.aspx" /&gt;
    &lt;/customErrors&gt;
      &lt;/system.web&gt;
  &lt;/configuration&gt;`
  </code></pre>
  
  <p>I am currently receiving a configuration parse error message: <em>Logon failure: unknown user name or bad password</em> when I tried to log on with my Windows credentials of my machine within the intranet.</p>
  
  <p>The error pointed out line </p>
  
  <pre><code>&lt;add name="MyADMembershipProvider" 
       type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" 
       applicationName="SOD" 
       connectionStringName="ADConnectionString" 
       connectionUsername="domain\Username" 
       connectionPassword="Password" 
       attributeMapUsername="sAMAccountName" 
       enableSearchMethods="true" /&gt;
  </code></pre>
  
  <p>has an error.</p>
  
  <p>May I know which part of my code went wrong?</p>
  
  <hr>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I have filled in the actual credentials for the code </p>
  
  <pre><code>connectionUsername="domain\Username" connectionPassword="Password"
  </code></pre>
  
  <p>I am now able to login with the correct credentials, and I am also prompted wrong credential for incorrect log in attempts.</p>
  
  <p>When another user of different credential from the one I 'hardcoded' in the <code>connectionUsername</code> and <code>connectionPassword</code>, the user is still able to log on.</p>
  
  <p>However, my <em>LoginName</em> tool from the toolbox still shows the username of the 'hardcoded' credentials in the <code>connectionUsername</code> instead of the username of the logged in user.</p>
  
  <p>May I know why is it so?</p>