本文介绍了创建跨域的cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作区。我可以很轻松地创建的cookie。要创建一个cookie我用这code:

I am working on cookies. I am able to create cookies very easily. To create a cookie I am using this code:

HttpCookie aCookie = new HttpCookie("Cookie name");
aCookie.Value = "Value";
Response.Cookies.Add(aCookie); 

这code是为我好,这让我localhost作为主机。但是,问题就来了这里,当我尝试在这里添加一个域名,如:

This code is fine for me and it gives me localhost as Host. But the problem comes here when I try to add a domain name here like:

HttpCookie aCookie = new HttpCookie("Cookie name");
aCookie.Value = "Value";
aCookie.Domain = "192.168.0.11";
Response.Cookies.Add(aCookie); 

现在不产生该cookie。有什么建议?

Now the cookie is not generated. Any suggestions?

推荐答案

您只能将域设置为自己(当前站点)和自己的子域,出于安全原因。你不能任意站点设置cookie。

You can only set the domain to yourself (the current site) and sub-domains of yourself, for security reasons. You can't set cookies for arbitrary sites.

这篇关于创建跨域的cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 23:55