在www.a.com下放SetCookie.ashx,内容如下:
/// <summary>
/// $codebehindclassname$ 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class SetCookie : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
context.Response.Write("Hello World");
context.Response.AddHeader("P3P: CP", "CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE GOV");
MyCookie.SetCookie("testcookie", "wq", DateTime.Now.AddDays(3), "/", ".xn--kwsz0jorw.com");
}
public bool IsReusable
{
get
{
return false;
}
}
}
/// $codebehindclassname$ 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class SetCookie : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
context.Response.Write("Hello World");
context.Response.AddHeader("P3P: CP", "CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE GOV");
MyCookie.SetCookie("testcookie", "wq", DateTime.Now.AddDays(3), "/", ".xn--kwsz0jorw.com");
}
public bool IsReusable
{
get
{
return false;
}
}
}
在www.b.com的某个页面添加以下js:
<script src="http://www.a.com/SetCookie.ashx"></script>
访问上面添加了JS的www.b.com 某个页面,再访问www.a.com,发现cookie已经实现跨域共享。