0121 31 45 374
Qoute Icon

Dual records in the ASP.Net authentication table

Tim

I recently updated one of our sites to use a shared authentication database to save on the maintenance, but in doing so I messed something up and couldn’t work out why I was getting dual records of the user. To summarise what I’d done, I had updated the applicationName value from “/” to “SomeName” and then updated the values in the database to reflect these changes.

In addition to having duplicate records for the users, the LastActivityDate was only being altered on login and subsequent page requests were not being noted which was a problem as this system requires this data. I did look into alternative methods around this until I realised that one of dates for the user was actually being updated –just not the roles/membership one!

There are a number of posts discussing doing this pre-userbase which were about as useful as a chocolate fireman. I finally realised that I’d not added the provider node for the profiles which meant it was not only reverting to the old connection string named “LocalSqlServer” but it was also assigning “/” as the application name. After updating this node all’s fine and dandy again.

For future reference, you need to override 3 web.config settings to ensure your application is referencing the correct database and within each one add the <clear /> node otherwise your application is likely to inherit from the machine.config (I’d got that one!!):

Web.Config Settings

<membership defaultProvider="YourMembershipProvider">
    <providers>
        <clear />
        <add name="YourMembershipProvider" 
         applicationName="YourApplicationName" 
         connectionStringName="YourASPNetSqlServerConn"
         type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> 
    </providers>
</membership>

<roleManager>
    <providers>
        <clear/>
        <add name="YourRoleProvider" 
         connectionStringName="YourASPNetSqlServerConn" 
         applicationName="YourApplicationName" 
         type="System.Web.Security.SqlRoleProvider" />
    </providers>
</roleManager>

<profile enabled="true" defaultProvider="YourProfileProvider">
  <providers>
    <clear />
    <add name="YourProfileProvider"
         connectionStringName="YourASPNetSqlServerConn"
         applicationName="YourApplicationName"
         type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
  </providers>
</profile>

Liked this post? Got a suggestion? Leave a comment