Project Description
Implementation of a ASP.NET 4.0 Membership, Role and Profile provider for SQL Server Compact 4.0, for use with Forms Authentication for web sites.

Breaking news - stop using this library

A Microsoft supplied Provider has been released on Nuget.org, I recommend that you use this going forward, this provider support all SQL Server 2005+ platforms, including SQL Server Compact 4.0. More information available here

How to use the provided files (2 simple steps)

NB: If you are using the NuGet package, only setting roleManager - enabled=true is required.


1. Copy the four files in the /App_Code folder to your web sites' ~/App_Code folder.

2. Modify your web.config using the following template (see the enclosed web.config):

<connectionStrings>
    <add name="ApplicationServices" connectionString="data source=|DataDirectory|\SqlCeAspnetdb.sdf"/>
</connectionStrings>

<system.web>
   <compilation>
      <assemblies>
         <add assembly="System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91"/>
      </assemblies>
   </compilation>
   <authentication mode="Forms">
    <forms loginUrl="~/Account/Login.aspx" timeout="2880"/>
   </authentication>
    <membership defaultProvider="SqlCeMembershipProvider">
      <providers>
        <clear/>
        <add 
              name="SqlCeMembershipProvider" 
              type="ErikEJ.SqlCeMembershipProvider" 
              connectionStringName="ApplicationServices" 
              applicationName="/" 
              enablePasswordRetrieval="false" 
              enablePasswordReset="true" 
              requiresQuestionAndAnswer="false" 
              requiresUniqueEmail="true" 
              passwordFormat="Hashed" 
              encryptionKey="FF09F72BA97CBBB5EEAAFF"
              writeExceptionsToEventLog="false" />
      </providers>
    </membership>
    <roleManager defaultProvider="SqlCeRoleProvider" 
            enabled="true" 
            cacheRolesInCookie="true" 
            cookieName=".ASPROLES" 
            cookieTimeout="30" 
            cookiePath="/" 
            cookieRequireSSL="false" 
            cookieSlidingExpiration="true" 
            cookieProtection="All">
      <providers>
        <clear/>
        <add 
            name="SqlCeRoleProvider" 
            type="ErikEJ.SqlCeRoleProvider" 
            connectionStringName="ApplicationServices" 
            applicationName="/" 
            writeExceptionsToEventLog="true"/>
      </providers>
    </roleManager>
  </system.web>

That's it - you can now create users, roles and use the ASP.NET login controls.

Site file layout (to verify that the provider is working):

sqlceprov.png

If you encounter any bugs, have suggestions or any other issues, please provide feedback here

Last edited Mar 29, 2013 at 7:48 AM by ErikEJ, version 31