Usage of StateServer in session

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.