views:

813

answers:

1

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, Im trying to teach myself 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);
+2  A: 

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
Gio
Updated, check it out.
Mehdi Golchin
Ah. Thanks again Mehdi.
Gio