Distributed cross-origin Session sharing in Windows

Source: Internet
Author: User

Why is that? I found N Session sharing articles online, but I still cannot solve the problem directly.

I. The following is my own test. To prevent environment inconsistencies, the definition of this article is as follows:

1. IIS7.0

2. Asp.net site

3. StateServer mode. Database and custom configuration are not covered in this article.

4. 192.168.1.41 (Main Site Server, domain name: www.xxx.com), 192.168.1.43 (Business distribution server Domain Name: BDN1.xxx.com)

5. Cross-Domain implementation is only a cross-subdomain method. (Because SessonID sharing is read by the cookies in the root domain)

Ii. Configuration

Main Site Server web. config

1. <sessionState mode = "StateServer" stateConnectionString = "tcpip = 192.168.1.41: 42424" timeout = "60"/>

Change the mode to StateServer. By default, remote access is disabled and the Registry (regedit) needs to be enabled ),

Set

2.

Restrict the Cookie Domain to the root Domain name so that all subdomains at the next level can access this Cookie.

If you only want the Session to be in the root domain and set other cookies, you can use this method.

<SessionState sessionIDManagerType = "B2BSite. MySessionIDManager" mode = "StateServer" stateConnectionString = "tcpip = 192.168.1.41: 42424" timeout = "60"/>

    public class MySessionIDManager : SessionIDManager, ISessionIDManager    {        void ISessionIDManager.SaveSessionID(HttpContext context, string id, out bool redirected, out bool cookieAdded)        {            base.SaveSessionID(context, id, out redirected, out cookieAdded);            if (cookieAdded)            {                var name = "ASP.NET_SessionId";                var cookie = context.Response.Cookies[name];                cookie.Domain = "xxx.com";                cookie.Path = "/";            }        }    }

  

3. <machineKey decryptionKey = "fd69b2eb9a11e3063518f1932e314e4aa1577bf0b425f369" validationKey = "5F32295C31223A362286DD5777916FCD0FD2A8EF882783FD3E29AB1FCDFE931F8FA45A8E468B7A40269E50A748778CBB8DB2262D44A86BBCEA96DCA46CBC05C3" validation = "SHA1" decryption = "Auto"/>

Different machines generate inconsistent sessions. Therefore, you need to specify the MachineKey so that sessions generated by different machines can be read from each other.

Web. config

1. <sessionState mode = "StateServer" stateConnectionString = "tcpip = 192.168.1.41: 42424" timeout = "60"/>

Tcpip = StateServerIP of the master server. You can also leave it independently. I am here on the master server.

2.

3. <machineKey decryptionKey = "fd69b2eb9a11e3063518f1932e314e4aa1577bf0b425f369" validationKey = "5F32295C31223A362286DD5777916FCD0FD2A8EF882783FD3E29AB1FCDFE931F8FA45A8E468B7A40269E50A748778CBB8DB2262D44A86BBCEA96DCA46CBC05C3" validation = "SHA1" decryption = "Auto"/>

This machinekey must be the same as the machinekey of the master Site Server.

Note: This is also the most critical point. many files do not mention the site ID in IIS settings. The two websites must be the same. If the site ID of the master Site Server is 3, the site ID of the Business distribution server must also be 3. otherwise, you cannot access it. I have been stuck in this place for a long time. it is described on MSDN.

 

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.