Session sharing under. NET Master and level two domains

Source: Internet
Author: User

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

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.