如何设置不同域的cookie

如何设置不同域的cookie

本文介绍了如何设置不同域的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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 16:50