28. May 2006

ASP.NET 2.0 Membership and Role providers

 

OleDb (MS Access) Providers

 

Many web developers prefer MS Access Databases because they are much simpler to maintain and usually also not limited by Internet Providers as SQL Server Databases. This doesn't mean SQLServer isn't good. But it is often an overkill. Also usually the control over your SQL Database on a Internet Provider is very limited. With MS Access you have full control.

Unfortunately for ASP.NET 2.0 - Microsoft only provides SQL Server ASP.NET MemberShip and Role Providers. To overcome this problem I have assembled simple Membership and Role providers for MS Access (OleDb providers)

 

Provider configuration

Below is explained step by step how to configure the providers. The main configuration is made in the web.config file of your Application.

Machine Key :

For decryption and validation of Password data a machineKey section needs to be created within the web.config under <system.web>. The keys are Application specific Hex codes. You should use stronger keys than below.

<machineKey
validationKey="0123456789ABCDEF0123456789ABCDEF01234567,IsolateApps"
decryptionKey="0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF,IsolateApps"
validation="MD5"
decryption="AES"
/>

Connection :

The Binarywater.NETproviders are using the OleDbServices connectionString. This is defined in the web.config under <connectionStrings>. The following connection strings assumes that the Users.mdb MS Access database is under App_Data folder.

<add name="OleDbServices"
connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|Users.mdb"
providerName="System.Data.OleDb"
/>

Membership provider :

The Binarywater.NET membership provider needs to be declared in the web.config under <system.web>. The provider works through multiple application. Therefore you should define the applicationName property.

<membership defaultProvider="OleDbProvider" userIsOnlineTimeWindow="15">
<providers>
<add
name="OleDbProvider"
type="Binarywater.NET.ASP.Providers.OleDbMembershipProvider"
connectionStringName="OleDbServices"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="true"
maxInvalidPasswordAttempts="5"
applicationName="MyApplication"
writeExceptionsToEventLog="true" />
</providers>
</membership>

Role provider :

The Binarywater.NET role provider needs to be declared in the web.config under <system.web>. The provider works through multiple application. Therefore you should define the applicationName property.

<roleManager defaultProvider="OleDbRoleProvider" 
enabled="true"
cacheRolesInCookie="true"
cookieName=".ASPROLES"
cookieTimeout="30"
cookiePath="/"
cookieRequireSSL="false"
cookieSlidingExpiration="true"
cookieProtection="All" >
<providers>
<clear />
<add
name="OleDbRoleProvider"
type="Binarywater.NET.ASP.Providers.OleDbRoleProvider"
connectionStringName="OleDbServices"
applicationName="MyApplication"
writeExceptionsToEventLog="false" />
</providers>
</roleManager>

 

Provider installation

 

Download the Binarywater.Net OleDbProvider.zip

Copy the OleDbMembershipProvider.cs and OleDbRoleProvider.cs providers into the App_Code folder of your application.

Copy the User.mdb Database into the App_Data folder of your application. ( Or create a new Users.mdb database using the create.sql script file )

Now you should be able to use the ASP.NET Configuration to setup users and roles.

 

Feedback

If you have problems, suggestions, bug fixes or you are just happy about this little providers - please let me know :

eMail : source@binarywater.net

 

Have Fun!

Patrick