19

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);
abatishchev
  • 92,232
  • 78
  • 284
  • 421
Gio
  • 525
  • 2
  • 5
  • 7

1 Answers1

13

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.

Mehdi Golchin
  • 7,613
  • 2
  • 28
  • 36
  • 5
    So the next question is how does one grab the authentication cookie from the incoming request to pass to the outgoing request? – Blairg23 Mar 09 '16 at 18:25