Second-level domain name Cookie Problem and Solution 2

Source: Internet
Author: User

 

After all the processing procedures, use httpmodule to solve the problem in one go.

Using System;
Using System. Data;
Using System. configuration;
Using System. Web;
Using System. Web. Security;
Using System. Web. UI;
Using System. Web. UI. webcontrols;
Using System. Web. UI. webcontrols. webparts;
Using System. Web. UI. htmlcontrols;

///   <Summary>
/// Correctcookiedomainmodule abstract description
///   </Summary>
Public   Class Correctcookiedomainmodule: ihttpmodule // Inherit the ihttpmodule Interface
{
Public Correctcookiedomainmodule ()
{
}

# RegionIhttpmodule Member

Public void dispose () {}

Public VoidInit (httpapplication context)
{
//Subscribe to events in init
Context. endrequest+ = NewEventhandler (context_endrequest );
}

///   <Summary>
/// Correct the cookie domain at the end of the HTTP execution Pipeline
///   </Summary>
Void Context_endrequest ( Object Sender, eventargs E)
{
Httpcontext Context = (Httpapplication) sender). context;

String Domain =   " .Cnblogs.com " ;
String Cookiename = Formsauthentication. formscookiename;
Httpcookie = Context. response. Cookies [cookiename];
If (Cookie ! =   Null )
{
// Change the cookie domain to .cnblogs.com.
// In this way, cookies can be shared with all second-level domain names.
Cookie. Domain = Domain;

}
}

# Endregion
}

 

In web. Config

 

<? XML version = "1.0"?>
<Configuration xmlns = "http://schemas.microsoft.com/.NetConfiguration/v2.0">
<System. Web>
<Compilation DEBUG = "true"/>
<Httpmodules>
<Add name = "correctcookiedomainmodule" type = "customcomponents. correctcookiedomainmodule"/>
</Httpmodules>
<Authentication mode = "Windows"/>
</System. Web>
</Configuration>

 

 

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.