locked
ActiveDirectoryMembershipProvider Not Working RRS feed

  • Question

  • User-701365861 posted

    Ok, so i can't seem to get the ActiveDirectoryMembership provider to work with the Login control or by manually authenticating the user. I have followed the example here:

     http://msdn.microsoft.com/en-us/library/ms998347.aspx?ppud=4#paght000022_usingtheactivedirectorymembershipprovider

    My issue is that the authentication DOES occur but User.Identity.IsAuthenticated always is false and the user never gets redirected to the page specified in the web.config file. The login page just pops up again with the querystring populated as if I am not authenticated. I am not getting any exceptions and if I do it programatically I can see that the credentials ARE validated correctly. If I enter incorrect credentials I get the correct error message. 

    Web.Config:

    <?xml version="1.0"?>
    <configuration>
      <connectionStrings>
        <add name="ADConnectionString" connectionString="LDAP://mydomain.com" />
        <add name="LocalPolicyStore" connectionString="msldap://CN=MYDOMAIN,CN=Program Data,DC=mydomain,DC=com" providerName=""/>
      </connectionStrings>
      <appSettings />
      <system.web>
            <!--
                The <authentication> section enables configuration 
                of the security authentication mode used by 
                ASP.NET to identify an incoming user. 
            -->
        <authentication mode="Forms">
          <forms loginUrl="Login.aspx"
                 protection="All"
                 timeout="30"
                 name="miBenefitsAdminToolCookie"
                 path="/FormsAuth"
                 requireSSL="false"
                 slidingExpiration="true"
                 defaultUrl="AdministrationHome.aspx"
                 cookieless="UseCookies"
                 enableCrossAppRedirects="false"/>
        </authentication>
        <authorization>
          <deny users="?" />
          <allow users="*" />
        </authorization>
        <roleManager enabled="true" defaultProvider="RoleManagerAzManProvider" cacheRolesInCookie="true" cookieName=".ASPXROLES" cookiePath="/" cookieTimeout="30" cookieRequireSSL="false" cookieSlidingExpiration="true" createPersistentCookie="false" cookieProtection="All">
          <providers>
            <remove name="AspNetSqlRoleProvider"/>
            <add connectionStringName="LocalPolicyStore" applicationName="miBenefitsAdministration" name="RoleManagerAzManProvider" type="System.Web.Security.AuthorizationStoreRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, publicKeyToken=b03f5f7f11d50a3a"/>
          </providers>
        </roleManager>
        <membership defaultProvider="MembershipADProvider" >
          <providers>
            <add name="MembershipADProvider"
              type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, 
                    Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
                        connectionStringName="ADConnectionString"
                        connectionUsername="****\*****"            
                        connectionPassword="*****"
                        attributeMapUsername="sAMAccountName" />
       
          </providers>
        </membership>
    
      </system.web>
      <location path="Images">
        <system.web>
          <authorization>
            <allow users="*"/>
          </authorization>
        </system.web>
      </location>
      <location path="App_Themes">
        <system.web>
          <authorization>
            <allow users="*"/>
          </authorization>
        </system.web>
      </location></configuration>

      If I try to authenticate manually the exact same thing happens. I know what is happening - because of the authorization section which is not allowing anonymous access to any pages, so for some reason a valid login is not properly authenticating. What could be causing this behavior?

     Thanks!

    Wednesday, April 8, 2009 6:51 PM

Answers

  • User-701365861 posted

    I changed the name of my cookie (specified in the forms-authentication node) and it works now. Grrr.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 13, 2009 3:07 PM

All replies

  • User-701365861 posted

    More Info:

    If I remove the <authorization> section from the web.config:

        <authorization>
          <deny users="?" />
          <allow users="*" />
        </authorization>

    The login control WILL redirect me to the page specified in the defaultUrl property BUT the isAuthenticated method returns false and User.Identity.Name is blank. It is incredibly frustrating when you follow an example and you are not doing anything all that fancy and the stuff just doesn't work when it should work.

    Please help!

    Wednesday, April 8, 2009 7:10 PM
  • User-701365861 posted

    And even more info...

     I've gone back to trying to do it manually rather than using the login control (still following the example listed above) and I am not getting the following code (happens on the Login Button Click after Membership.Validate user is called and is valid):

    If Not Request.QueryString("ReturnUrl") Is Nothing Then
        FormsAuthentication.RedirectFromLoginPage(TextBoxUserId.Text, False)
    Else
        FormsAuthentication.SetAuthCookie(TextBoxUserId.Text, False)
    End If

    Request.QueryString("ReturnUrl") is always Nothing so FormsAuthentication.RedirectFromLoginPage never gets called. I am just not getting exactly what this code is supposed to be doing or why it is looking at the Request.QueryString("ReturnUrl") variable. If I remove the if statement and just call FormsAuthentication.RedirectFromLoginPage i get the exact same behavior as when using the login control.

    Thanks!

     

     

    Wednesday, April 8, 2009 7:22 PM
  • User-701365861 posted

    Nobody has any ideas?

    Monday, April 13, 2009 11:34 AM
  • User-701365861 posted

    I changed the name of my cookie (specified in the forms-authentication node) and it works now. Grrr.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 13, 2009 3:07 PM
  • User-964402675 posted

    could please post the corrected code... I am going through the same thing you were. 

    Monday, October 19, 2009 10:25 PM