.net framework 4.5下测试成功,使用RedisSessionStateProvider 2.2.1保持session数据,通过Haproxy保持会话数据。
首先在PM下安装RedisSessionStateProvider
Install-Package Microsoft.Web.RedisSessionStateProvider,修改web站点 web.config,使两个web站点的Redis配置相同。
<configuration> <appSettings> <add key="val" value="100"/> </appSettings> <system.web> <compilation debug="true" targetFramework="4.5" /> <httpRuntime targetFramework="4.5" /> <sessionState mode="Custom" customProvider="MySessionStateStore"> <providers> <add name="MySessionStateStore" type="Microsoft.Web.Redis.RedisSessionStateProvider" host="localhost" accessKey="" ssl="false" /> </providers> </sessionState> </system.web> </configuration>
测试站点index.aspx页面源码
1 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Index.aspx.cs" Inherits="WebApp.Index" %> 2 3 <!DOCTYPE html> 4 5 <html xmlns="http://www.w3.org/1999/xhtml"> 6 <head runat="server"> 7 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> 8 <title></title> 9 </head> 10 <body> 11 <form id="form1" runat="server"> 12 <div> 13 <asp:Button ID="btnSet" runat="server" OnClick="btnSet_Click" Text="Set Session" /> 14 </div> 15 </form> 16 </body> 17 </html>