Session StateServer mode is used in recent projects. We know that sessionstate has four modes: Off, inproc, StateServer, and sqlserver. While the States. StateServer is deployed on the same server site in my biggest sense. As long as the configurations are consistent, you can access the same session value. That is, the session can be accessed across sites. The usage is as follows:
The site configuration is as follows:
Web. config Configuration
<pre name="code" class="csharp"> <system.web> <authentication mode="Forms"> <forms name="SSOForm" loginUrl="~/Account/Login.aspx" defaultUrl="~/Default.aspx" timeout="2880" domain="test.com" /> </authentication> <!-- 开发与测试使用服务器内存记录 asp.net 状态 --> <!--<sessionState cookieName="AeroSessionId" mode="InProc" cookieless="false" timeout="100" />--> <!-- 正式环境使用专门的 asp.net 状态服务器来管理 asp.net 状态 --> <sessionState cookieName="SessionId2" cookieless="false" mode="StateServer" stateConnectionString="tcpip=127.0.0.1:42424" timeout="200" /> <!-- 网络之间的验证键 --> <machineKey validationKey="9912131415161718190a0b0c0d0e0f1011121314" decryptionKey="99225577bbaa9988" validation="SHA1" /> </system.web>
Global File override init event
public override void Init() { //session内部存储key的前缀 var sessionStateStoreProvider = typeof(HttpSessionState).Assembly.GetType("System.Web.SessionState.OutOfProcSessionStateStore"); var uriBaseField = sessionStateStoreProvider.GetField("s_uribase", BindingFlags.Static | BindingFlags.NonPublic); uriBaseField.SetValue(null, FormsAuthentication.CookieDomain); base.Init(); }
Then other sites can configure the same settings to pair sessionji with each other.
Usage of StateServer in session