System.Net.Cookie是表示客户端程序通过http响应接收到的Cookie,
System.Web.HttpCookie是服务器端通过http请求从客户端获取的Cookie
从网上看的资料,大部分都是以上2局。还是有点不太懂
1、System.Net.Cookie和System.Web.HttpCookie有什么区别?
2、两者通常在什么情况下使用?
------最佳解决方案--------------------
System.Net.Cookie是表示客户端程序通过http响应接收到的Cookie,而System.Web.HttpCookie是服务器端通过http请求从客户端获取的Cookie,比如下面这个winform程序通过向指定的url发送包含cookie的web请求然后获取返回的响应的代码:
]
WebRequestObject = (HttpWebRequest) WebRequest.Create( "http://www.webdiyer.com/cookietest.aspx ");
WebRequestObject.Method = "GET ";
System.Net.CookieContainer CookieContainerObject = new System.Net.CookieContainer();
System.Net.Cookie Cookie = new System.Net.Cookie();
Cookie.Name = "userid ";
Cookie.Value = "1234567890 ";
Cookie.Domain = Request.ServerVariables[ "HTTP_HOST "];
Cookie.Secure = true;
CookieContainerObject.Add(Cookie);
WebRequestObject.CookieContainer = CookieContainerObject;
WebResponseObject = (HttpWebResponse) WebRequestObject.GetResponse();
sr = new StreamReader(WebResponseObject.GetResponseStream());
String Results = sr.ReadToEnd();
------其他解决方案--------------------
如果楼主还是不明白,可以看看他们在msdn文档里面说明,或者看看链接示例