一 网站项目引入"mysql.web.dll"
二 web.config配置中添加mysql数据库连接字符串
<connectionStrings>
<remove name="LocalMySqlServer" />
<add name="LocalMySqlServer" connectionString="server=localhost;user=root;pwd=1234;database=mydatabase;" providerName="MySql.Data.MySqlClient" />
</connectionStrings>
三 配置sessionState节点
<sessionState cookieless="false" regenerateExpiredSessionId="true" mode="Custom" timeout="30" customProvider="MySqlSessionStateProvider">
<providers>
<add name="MySqlSessionStateProvider"
type="MySql.Web.SessionState.MySqlSessionStateStore, MySql.Web, Version=6.9.8.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"
applicationName="/mywebapp"
description="MySQL Session State"
connectionStringName="LocalMySqlServer"
writeExceptionsToEventLog="False"
autogenerateschema="True"
enableExpireCallback="False" />
</providers>
</sessionState>
配置说明:
mode: sessionState模式,"Custom"为自定义模式;
timeout: session过期时间,默认20分钟.
customProvider: 自定义Provider,与providers节点下添加的名称对应;
applicationName: 应用名称,可自定义,用于区分不同网站应用的session数据;
connectionStringName: 数据库连接字符串名称;
autogenerateschema: 是否自动生成数据库表,网站会将session相关数据保存到mysql数据库对应的表中,
这些表可以手动创建,也可以自动创建.
参考文章:
http://www.codeproject.com/Articles/633199/Using-MySQL-Session-State-Provider-for-ASP-NET