Asp.net second-level domain name sharing session based on StateServer, stateserversession

Source: Internet
Author: User

Asp.net second-level domain name sharing session based on StateServer, stateserversession

Note: The trial is effective in person. If the user does not share the session through the following tutorial, leave a message to describe your problem. Yes.

Recently, the shared session for second-level domain names has struggled for a long time. Many implementation methods on the Internet cannot be used. It takes a long time to find the implementation method. Record it here for future use.

The second-level domain name sharing session has multiple implementation methods: the first is dependent on cookies. Second, directly share the session.

Here I am sharing the second method of directly sharing sessions. Session storage methods include InProc, StateServer, and SQLServer.

The stored party's Test Based on StateServer is shared here.

Implementation idea: Make the ASP. NET_SessionId of the primary domain name and the second-level domain name consistent.

Steps:

Step 2. Change the sessionState storage method to StateServer. The default value is InProc. Tcpip = 127.0.0.1: 42424 this section refers to the meaning of the local machine. I tested that both the primary domain name and the second-level domain name are on one server. For example, in the red box area:

Step 2. Add the node

To view ASP. NET_SessionId, you can open the webpage in the google browser, and then F12. view ASP. NET_SessionId on the following panel.

Step 2 Add the following code to Global. asax.

   public override void Init()    {        base.Init();        foreach (string moduleName in this.Modules)        {            string appName = "APPNAME";            IHttpModule module = this.Modules[moduleName];            SessionStateModule ssm = module as SessionStateModule;            if (ssm != null)            {                System.Reflection.FieldInfo storeInfo = typeof(SessionStateModule).GetField("_store", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);                SessionStateStoreProviderBase store = (SessionStateStoreProviderBase)storeInfo.GetValue(ssm);                if (store == null)//In IIS7 Integrated mode, module.Init() is called later                {                    System.Reflection.FieldInfo runtimeInfo = typeof(HttpRuntime).GetField("_theRuntime", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic);                    HttpRuntime theRuntime = (HttpRuntime)runtimeInfo.GetValue(null);                    System.Reflection.FieldInfo appNameInfo = typeof(HttpRuntime).GetField("_appDomainAppId", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);                    appNameInfo.SetValue(theRuntime, appName);                }                else                {                    Type storeType = store.GetType();                    if (storeType.Name.Equals("OutOfProcSessionStateStore"))                    {                        System.Reflection.FieldInfo uribaseInfo = storeType.GetField("s_uribase", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic);                        uribaseInfo.SetValue(storeType, appName);                    }                }            }        }    }

OK, the primary domain name and second-level domain name can all implement the above three steps. This article is to carry pot filling Original Articles, reprint please note the original address: http://www.cnblogs.com/liaohuolin/p/4502554.html

Related Article

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.