Last post Dec 20, 2018 07:54 PM by jzero
Mar 12, 2005 02:04 PM|ubelt|LINK
Mar 12, 2005 06:02 PM|haidar_bilal|LINK
Feb 11, 2009 05:14 AM|makhm|LINK
The link seems to be broken. I'm looking for the same thing too :(
Feb 11, 2009 05:37 AM|Mr^B|LINK
You'll need to add a reference to System.Web.
Then you'll need to use the current HttpContext to get at the cookies.
This is BAD, very BAD, BAD^100, BAD++, BAD#
A class should have NO knowledge of cookies, or know anything about them, unless it's a specific cookie handler, and even then it should NEVER EVER have to access the HttpContext in that way.
If your class has to deal with cookies, then consider passing in the VALUE of the cookie, rather than the cookie itself.
For more on this, do some googling for "dependency injection".
Dec 19, 2018 03:24 AM|mcm|LINK
@Mr^B It's helpful if you explain why it's bad to help educate us on the issues that can arise if you did access cookies from a library class.
I can understand that if it's used to configure service behaviour then this creates a dependency on cookies making it harder to store configuration in a different location if needed later. So it's better to decouple.
However, in our case we're building a service to retrieve configuration and implementation supports reading from cookies. This seems a legitimate scenario for a class in a library to know about cookies, because the users of the library are free to build their
own implementation that retrieves configuration from a different source and then configure dependency injection to use that instead.
Dec 20, 2018 07:54 PM|jzero|LINK
If using HttpWebRequest, you have to initialize CookieContainer before call HttpWebResponse. If you don´t do that, HttpWebResponse.Cookies = nothing
Dim URL = "http://www.whatever.com"
Dim HttpReq As HttpWebRequest = CType(WebRequest.Create(pURL), HttpWebRequest)
HttpReq.CookieContainer = New CookieContainer
Dim HttpRes As HttpWebResponse = CType(HttpReq.GetResponse, HttpWebResponse)