关闭

.NET中COOKIES跨域解决办法

标签: cookies.netnullstring
685人阅读 评论(0) 收藏 举报
分类:
简单代码如下:———————————————————————————————————
更新cooikes
//如果存在cookie,则更新value属性;否则,new一个cookie。
HttpCookie cookies = Request.Cookies["userName"];
if (cookies == null)
{
cookies = new HttpCookie("userName", this.txtUserName.Text);
cookies.Domain = ".vip8848.cn";
Response.Cookies.Set(cookies);
}
else
{
cookies.Value = this.txtUserName.Text;
cookies.Domain = ".vip8848.cn";
Response.Cookies.Set(cookies);
cookies = new HttpCookie("userName", this.txtUserName.Text);

}
读出COOKIES
HttpCookie cookies = Request.Cookies["userName"];
if (cookies != null)
{

this.TextBox1.Text = cookies.Value;
}
查看所有的COOKIES
HttpCookieCollection cookies;
HttpCookie oneCookie;
cookies = Request.Cookies;
string[] cookieArray = cookies.AllKeys;
for (int i = 0; i < cookieArray.Length; i++)
{

oneCookie = cookies[cookieArray[i]];

Response.Write(oneCookie.Name + " - " + oneCookie.Value);
}
 
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:60574次
    • 积分:1291
    • 等级:
    • 排名:千里之外
    • 原创:66篇
    • 转载:7篇
    • 译文:0篇
    • 评论:12条
    优化蜘蛛引导