1 Public classCrossdomaincookie:ihttpmodule2 {3 Private stringM_rootdomain =string. Empty;4 5 #regionIHttpModule Members6 7 Public voidDispose ()8 {9 Ten } One A Public voidInit (HttpApplication context) - { -M_rootdomain = configurationmanager.appsettings["Rootdomain"]; the -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"); + AUrifield.setvalue (NULL, m_rootdomain); at -Context. EndRequest + =NewSystem.EventHandler (context_endrequest); - } - - voidContext_endrequest (Objectsender, System.EventArgs e) - { inHttpApplication app = Sender asHttpApplication; - to for(inti =0; I < App. Context.Response.Cookies.Count; i++) + { -App. Context.response.cookies[i]. Domain =M_rootdomain; the } * } $ Panax Notoginseng #endregion -}
Config inside configuration: (note two sites are to be configured)
1<configuration>2<appSettings>3<add key="Rootdomain"Value=". session.com"/>4</appSettings>5<connectionStrings/>6<system.web>7<machinekey decryptionkey="fd69b2eb9a11e3063518f1932e314e4aa1577bf0b824f369"validationkey="5f32295c31223a362286dd5777916fcd0fd2a8ef882783fd3e29ab1fcdfe931f8fa45a8e468b7a40269e50a748778cbb8db2262d44a86bbcea96d CA46CBC05C3"validation="SHA1"decryption="Auto"/>8<sessionstate cookieless="false"timeout=" -"Mode="StateServer"stateconnectionstring="tcpip=127.0.0.1:42424"/>9Ten<add name="Crossdomaincookiemodule"Type="Weblibrary.crossdomaincookie, Weblibrary"/> One A<pages controlrenderingcompatibilityversion="3.5"Clientidmode="autoid"/> -</system.web> -<!-- theThe system.webserver section isRequired forrunning ASP. NET AJAX under Internet -Information Services7.0. It isNot necessary forPrevious version of IIS. -- -<system.webServer> +<modules> -<add name="Crossdomaincookiemodule"precondition="Managedhandler"Type="Weblibrary.crossdomaincookie, Weblibrary"/> +</modules> A</system.webServer> at</configuration>
Session sharing under. NET Master and level two domains