简体   繁体   中英

Write cookies from subdomain and read from another subdomain without changing web.config

I have a simple question. I have two different projects like

http://login.mydomain.com

and

http://test.mydomain.com

. As it's name suggests, I login from login project and response redirect to test project.

I am able to create cookie for login.mydomain.com but I can not read it from test.mydoamin.com.
My question is can I create cookie from login.mydomain.com to www.mydomain.com and read it from test.mydomain.com as if I am reading it from www.mydomain.com .


This is how I create my cookies.

Response.Cookies["UserValidForMyDomain"].Value = myvalue;
Response.Cookies["UserValidForMyDomain"].Expires = dtExpireDate;

and how I read them.

string myValue = Request.Cookies["UserValidForMyDomain"].Value;

否,但是您可以为.mydomain.com的域创建一个通配符cookie,这将允许任何子域读取/写入它。

TO WRITE

HttpCookie hc = new HttpCookie("key", "value");
hc.Domain = ".mydomain.com";
hc.Expires = DateTime.Now.AddMonths(3);
HttpContext.Current.Response.Cookies.Add(hc);

TO READ

HttpContext.Current.Request.Cookies["key"].Value

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM