문제

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top