1

Does anyone have some good direction on how to debug a .NET Login control that always returns false?

I am developing a simple .NET application that authenticates against Active Directory. I am following the example given at this url: http://geekswithblogs.net/frankw/archive/2008/05/18/forms-authentication-with-active-directory-in-asp.net-2.0.aspx

After working out a few configuration hiccups, I have the form loading and appears to be working but it always returns false. I am using an LDAP connection string that works in another application so that's not the issue.

I am looking for ways to debug the Login control in order to see where things are falling apart. I see a couple javascript functions that I assume are generated by the login control but they lead to a dead end when the function: ValidatorCommonOnSubmit() is called. That function is not found in the code on the page - so it must in an include somewhere?

Does anyone have some good direction on how to debug a .NET Login control that always returns false?

Here is web.config. These settings work when I use them in a MVC app - but not in webforms. ??

<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <connectionStrings>
    <add name="ADConnectionString" connectionString="LDAP://thing.mycompany.com:389/CN=users,DC=mycompany,DC=com" />
  </connectionStrings>
  <system.web>
    <customErrors mode="Off"/>
    <compilation debug="true" targetFramework="4.5.1" />
    <httpRuntime targetFramework="4.5.1" />
    <pages>
      <namespaces>
        <add namespace="System.Web.Optimization" />
      </namespaces>
      <controls>
        <add assembly="Microsoft.AspNet.Web.Optimization.WebForms" namespace="Microsoft.AspNet.Web.Optimization.WebForms" tagPrefix="webopt" />
      </controls>
    </pages>

    <authentication mode="Forms">
      <forms name=".ADAuthCookie" timeout="10"
              loginUrl="Login.aspx" defaultUrl="Default.aspx">
      </forms>
    </authentication>
    <authorization>
      <deny users="?"/>
    </authorization>
    <profile defaultProvider="DefaultProfileProvider">
      <providers>
        <add name="DefaultProfileProvider" type="System.Web.Providers.DefaultProfileProvider, System.Web.Providers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />
      </providers>
    </profile>

    <membership defaultProvider="DomainLoginMembershipProvider">
      <providers>
        <clear />
        <add name="DomainLoginMembershipProvider"
             type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
             connectionStringName="ADConnectionString"
             attributeMapUsername="sAMAccountName"
             connectionUsername="username"
             connectionPassword="password"
             connectionProtection="Secure"
             enableSearchMethods="True"
             attributeMapEmail="mail"
             applicationName="/"
        />

      </providers>
    </membership>
    <roleManager defaultProvider="DefaultRoleProvider">
      <providers>
        <add name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />
      </providers>
    </roleManager>
    <!--
            If you are deploying to a cloud environment that has multiple web server instances,
            you should change session state mode from "InProc" to "Custom". In addition,
            change the connection string named "DefaultConnection" to connect to an instance
            of SQL Server (including SQL Azure and SQL  Compact) instead of to SQL Server Express.
      -->
    <sessionState mode="InProc" customProvider="DefaultSessionProvider">
      <providers>
        <add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" />
      </providers>
    </sessionState>
  </system.web>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="DotNetOpenAuth.Core" publicKeyToken="2780ccd10d57b246" />
        <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="DotNetOpenAuth.AspNet" publicKeyToken="2780ccd10d57b246" />
        <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
</configuration>
rgalpin
  • 137
  • 1
  • 13
  • Check the web.config, this is usually by a bad cookie setup - login is base on the cookies, if the cookie is not correctly set, then its fails – Aristos Oct 21 '14 at 21:55
  • I added the web.config here. See any issues? – rgalpin Oct 23 '14 at 14:52
  • I see that you do not have set the `domain` parameter on `authentication` lines, check this answer is very close http://stackoverflow.com/questions/12506532/session-would-not-retain-values-and-always-return-null/12506833#12506833 – Aristos Oct 23 '14 at 18:17
  • It turned out the issue was with the LDAP connection string. When I removed the query string from the connection string it worked. I don't understand why. The LDAP connection string that worked was: LDAP://thing.mycompany.com. – rgalpin Oct 27 '14 at 21:10

1 Answers1

0

It turned out the issue was with the LDAP connection string. When I removed the query string from the connection string it worked. The LDAP connection string that worked was: LDAP://thing.mycompany.com.

The way that I finally came to this answer was when I started doing searches specifically on ActiveDirectoryMembershipProvider instead of focusing on the Login control itself. Thanks to Aristos who pointed me toward the web.config and away from the form.

rgalpin
  • 137
  • 1
  • 13