之间的HttpCookie和cookie中的区别? [英] The difference between HttpCookie and Cookie?

查看:834
本文介绍了之间的HttpCookie和cookie中的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我很困惑,MSDN和其他教程告诉我用HttpCookies通过Response.Cookies.Add(饼干)来添加饼干。但是,这就是问题所在。 Response.Cookies.Add只接受Cookies和不HttpCookies,我得到这个错误:



无法从System.Net.CookieContainer'转换为'System.Net.Cookie



此外,什么是Response.Cookies.Add(饼干)和Request.CookieContainer.Add(饼干)?


$ b $之间的差异b

感谢提前的帮助下,我想用C#来教自己。

  //曲奇
曲奇myCookie时=新的Cookie();
MyCookie.Name =SID;
MyCookie.Value = SID;
MyCookie.HttpOnly = TRUE;
MyCookie.Domain =.domain.com;

//的HttpCookie
的HttpCookie myCookie时=新的HttpCookie(SID);
MyCookie.Value = SID;
MyCookie.HttpOnly = TRUE;
MyCookie.Domain =.domain.com;

Response.Cookies.Add(myCookie时);


解决方案

您正在使用系统。 Net.HttpWebResponse 。但上面的例子中使用 System.Web.HttpResponse 这需要 System.Web.HttpCookie 作为参数。



斯科特 - 阿伦




System.Web.HttpRequest是在服务器上,一个ASP.NET
应用程序内部类中使用
。它代表了
从客户端的传入的要求。



System.Net.HttpWebRequest是一类
用来做一个的传出的请求,
A Web应用程序。



So I'm confused as msdn and other tutorials tell me to use HttpCookies to add cookies via Response.Cookies.Add(cookie). But that's the problem. Response.Cookies.Add only accepts Cookies and not HttpCookies and I get this error:

cannot convert from 'System.Net.CookieContainer' to 'System.Net.Cookie'

Additionally, what's the difference between Response.Cookies.Add(cookie) and Request.CookieContainer.Add(cookie)?

Thanks for the help in advance, I'm trying to teach myself using C#.

// Cookie
Cookie MyCookie = new Cookie();
MyCookie.Name = "sid";
MyCookie.Value = SID;
MyCookie.HttpOnly = true;
MyCookie.Domain = ".domain.com";

// HttpCookie
HttpCookie MyCookie = new HttpCookie("sid");
MyCookie.Value = SID;
MyCookie.HttpOnly = true;
MyCookie.Domain = ".domain.com";

Response.Cookies.Add(MyCookie);

解决方案

You are using System.Net.HttpWebResponse. But the above example uses System.Web.HttpResponse which takes System.Web.HttpCookie as a parameter.

Scott Allen

System.Web.HttpRequest is a class used on the server and inside an ASP.NET application. It represents the incoming request from a client.

System.Net.HttpWebRequest is a class used to make an outgoing request to a web application.

这篇关于之间的HttpCookie和cookie中的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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