. NET multi-site implementation session sharing via StateServer

Source: Internet
Author: User

The <system.web> node for all sites that want to share Web. config is added first.

<!--session of Mode=stateserver-->
<sessionstatecookieless= "false"Timeout= " the"Mode= "StateServer"stateconnectionstring= "tcpip=127.0.0.1:42424"/>
<!--machine code to be unified--<MachineKeydecryptionkey= "fd69b2eb9a11e3063518f1932e314e4aa1577bf0b824f369"validationkey= "5f32295c31223a362286dd5777916fcd0fd2a8ef882783fd3e29ab1fcdfe931f8fa45a8e468b7a40269e50a748778cbb8db2262d44a86bbcea9 6DCA46CBC05C3 "Validation= "SHA1"decryption= "Auto"/> <httpmodules>

<add name= "Crossdomaincookiemodule" type= "Weblibrary.crossdomaincookie, weblibrary"/>
    </ httpmodules >

Create a new class library project code as follows

usingsystem.web;usingSystem;usingSystem.Configuration;usingSystem.Diagnostics;usingSystem.Reflection;usingSystem.Web.SessionState; namespaceWeblibrary { Public classCrossdomaincookie:ihttpmodule {Private stringM_rootdomain ="http://localhost:8008/";//main shared session URL, here Tester so with Locahlost, can also use domain name#regionIHttpModule Members Public voidDispose () {} Public voidInit (HttpApplication context) {M_rootdomain= configurationmanager.appsettings["Rootdomain"]; Type Stateserversessionprovider=typeof(HttpSessionState). Assembly.GetType ("System.Web.SessionState.OutOfProcSessionStateStore"); FieldInfo Urifield= Stateserversessionprovider.getfield ("S_uribase", BindingFlags.Static |bindingflags.nonpublic); if(Urifield = =NULL)                 Throw NewArgumentException ("Urifield is not found"); Urifield.setvalue (NULL, M_rootdomain); Context. EndRequest+=NewSystem.EventHandler (context_endrequest); }         voidContext_endrequest (Objectsender, System.EventArgs e) {HttpApplication app= Sender asHttpApplication;  for(inti =0; I < App. Context.Response.Cookies.Count; i++) {app. Context.response.cookies[i]. Domain=M_rootdomain; }         }         #endregion     } }

If StateServer is not 127.0.0.1 for the remote server, modify the entries in the session server registry for the remote server IP address IPAddress hkey_local_machine\system\ The value of the Allowremoteconnection key in CurrentControlSet\Services \aspnet_state\parameters is 1, where the port key controls the ASP. The service's listening port, which requires the restart of the ASP. NET State service to take effect after modification;

. NET multi-site implementation session sharing via StateServer

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.