开发者

Across Cookie in Domain in Subdomain

开发者 https://www.devze.com 2023-04-06 10:32 出处:网络
I have two application in my work Asp.Net MVC and PHP. PHP is my domain. MVC is my subdomain. php when creating the cookie looks like this -

I have two application in my work Asp.Net MVC and PHP.

PHP is my domain.

MVC is my subdomain.

php when creating the cookie looks like this -

u%3Dxxxxxx%40xxxxxx.com%26e%3D20%2F9%2F2011+17%3A05%3A04%26c%3D4c059a5开发者_运维技巧3d2134867fdb64b44714f2463

and

mvc when creating the cookie looks like this -

u=xxxx@xxxxx.com&e=20/9/2011 20:04:12&c=8CDC334D509AED502402AAF3537DD226

the domain in cookie = .xxx.com

But when i try to read the cookie in Mvc the cookie dont work.

cookie["u"]
cookie["e"]
cookie["c"]

What might be going wrong?

Thank you

Sorry my english


You should ensure that when the cookie is created (on the PHP site), the Set-Cookie header looks like this:

Set-Cookie: u=some_value; domain=example.com

Now you will be able to access this cookie from any subdomain on example.com. Inside the ASP.NET MVC application you can access it like this:

public ActionResult Index()
{
    var cookie = Request.Cookies["u"];
    ...
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号