.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>
View Code

相关文章:

  • 2021-10-07
  • 2021-09-11
  • 2021-07-13
  • 2021-11-16
  • 2021-07-24
  • 2021-10-15
  • 2021-06-22
猜你喜欢
  • 2021-09-26
  • 2022-12-23
  • 2021-11-10
  • 2022-01-02
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案