如何设置不同域的cookie [英] How to set cookie of a different domain

查看:928
本文介绍了如何设置不同域的cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解不可能在完全不同的域中共享Cookie,但如果有其他替代方法,请告诉我们。我的方案如下:



在我的网络应用程序上有一个页面(www.mydomain.com/somepage.aspx)。访问此页面时,在页面加载时,我使用HttpWebRequest对象向另一个网站(www.anotherdomain.com/Login.aspx)执行GET请求以获取必要的cookie,以便稍后在POST请求中发送它页面。



在GET请求的HttpWebResponse中,我得到一个cookie,我需要以相同的域名(www.anotherdomain.com)以编程方式存储在浏览器上br />


问题是,当我添加我在域中的响应中的cookie(我做了HttpWebRequest)时,没有添加cookie。



我需要将该cookie存储在浏览器中,因为Login.aspx页面需要它才能让用户通过登录页面而无需输入凭据。



我怎样才能成功完成这个场景?

I understand that is not possible to share cookies across totally different domains but if there is another alternative please let me know. My scenario is as following:

On my web application there is one page (www.mydomain.com/somepage.aspx). When this page is visited, On Page Load, I do a GET Request with HttpWebRequest object to another website (www.anotherdomain.com/Login.aspx) to obtain a necessary cookie in order to send it later in a POST request at the same page.

Within the HttpWebResponse of the GET Request I get one cookie that I need to store on the browser programmatically with the same domain (www.anotherdomain.com)

The problem is that when I add that cookie that is in my response with the domain (which I made the HttpWebRequest) cookie is not added.

I need to store that cookie in the browser because the Login.aspx page require it in order to let the user pass the login page without the need of entering the credentials.

How could I successfully accomplish this scenario?

推荐答案

如果我正确理解你的场景你想存储来的cookie来自页面中的一个域属于另一个域。我认为cookie与特定域相关联.HttpCookie有一个属性,其中包含cookie的域。



我认为您可以尝试为此方案设置Domain属性。
If I understand your scenario correctly you want to store the cookie that comes from one domain in page belonging to another domain.I think cookie is associated with a particular domain.HttpCookie has a property Domain which contains the domain of the cookie.

I think you can try to set the Domain property for this scenario.


这篇关于如何设置不同域的cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆