Introduction
This article describes how to set-up an ASP.NET project in order to use MySql as its session state store provider.
Using the code
Looking on the web I was not able to find a suitable solution that uses MySql as its session state store. It may certainly be possible that there is already a better solution available (if so, please do not hesitate to contact me). However, I was able to find a sample session state store provider using MS Access. That's it! Port it to MySql ... and that's what I did.
But, let's do it step by step. The list below gives you an idea on what I did in order to get it to work:
Downloaded the sample session state store provider for MS Access from
MSDN.
Downloaded the .NET Connector (using version 5.0.7) from
MySql.
Ported the sample code provided by Microsoft for use with MySql (the zipped source code can be found
here).
Adjusted the Web.config accordingly:
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<connectionStrings>
<add name="MySqlSessionServices" connectionString="Database=<name of database>; Data Source=<host>; User Id=<login>; Password=<password>"/>
</connectionStrings>
<system.web>
<sessionState cookieless="false" regenerateExpiredSessionId="true" mode="Custom" customProvider="MySqlSessionProvider">
<providers>
<add name="MySqlSessionProvider" type="Samples.AspNet.Session.MySqlSessionStateStore" connectionStringName="MySqlSessionServices" writeExceptionsToEventLog="false"/>
</providers>
</sessionState>
</system.web>
</configuration>
Download Code Here