[Obscure.NET] Finding existing cookies

Started by
7 comments, last by Cedric 20 years, 8 months ago
I need to log on to a site (like GameDev) that stores its password info in a cookie on the user's computer. I know the stupid cookie's name, location, exact filename (it's on my computer). Now, how do I load it into a System.Net.Cookie? Any ideas on where I might even find this kind of info? I've scoured the Usenet groups, but every post assumed that I would receive the cookie from a request and store it myself, with a key. But what is that key? How do I find it for an existing cookie?? Also, every page I found assumed that I had an object (or class) named Request. They would write: Cookie mycookie = Request.Cookies(someKeyString); But I don't have a Request object/class! I think that they're mixing ASP.Net and C#, and it's not very stranger-friendly. I'm just looking for a static function somewhere that returns a CookieCollection that contains all the cookies on this computer. Can anyone help? Cédric [edited by - Cedric on August 13, 2003 12:17:58 AM]
Advertisement
quote:Original post by Cedric
I know the stupid cookie''s name, location, exact filename (it''s on my computer).

Uhm, browsers store the cookies in various ways - there is no one way to store a cookie on the user''s HD. I doubt they made the cookie class in such a way that it could load all the various storage forms.


AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
Ah, an answer! Thank you!

I know that different browsers do it differently. But my program is not destined for public consumption. The computer where it will be installed will always be using XP and IE.

quote:I doubt they made the cookie class in such a way that it could load all the various storage forms

That would make sense, I guess. Then what can I do? I have to enter my username and my password in a text box on the web page, and press Submit to get the cookie. Isn''t it going to be very painful to do that with requests and such?

And no, I don''t know the cookie format, and looking at its content, I won''t be able to decrypt it myself.

Cédric
Cedric, you really should read the documentation. You might also want to get a book on ASP.Net because it''s clear that you do not have an understanding of ASP.Net. The Request object is available to every single asp page that you create. So you can ideed call : Request.Cookies("yourCookieName") to retrieve the cookie.
quote:Original post by bslayerw
Cedric, you really should read the documentation. You might also want to get a book on ASP.Net because it''s clear that you do not have an understanding of ASP.Net. The Request object is available to every single asp page that you create. So you can ideed call : Request.Cookies("yourCookieName") to retrieve the cookie.

I have never, ever done anything with ASP consciously, in my life, nor have I read any of its documentation. So no, I don''t understand ASP.

I am not trying to build a web page; I''m trying to use C# auomatize the downloading of data from a web site that asks me for a password. If the web page didn''t ask for a password, I would simply use a WebRequest. Trivial, and it has nothing to do with ASP.Net AFAIK. The requests can even have cookies attached to them. BUT, it seems that the only way to get a cookie is to send another request, and check the cookies that it has received. I don''t know how to send the request along with my username and password to get the cookie.

Cédric
To be honest, I''m confused about the whole thing, and not even sure that it is stored in a cookie. The page didn''t ask me for my password one day after my registration (I had rebooted my computer), but it asked me today.

The web page is
Wall Street City registration

That''s not a .asp page. But it''s in a cgi-bin directory.

Cédric
You will need to log in using the WebRequest class as well. Probably the best thing for you to do is use a packet sniffer(Ethereal?) to find out what exactly the browser is sending when you click the login button after filling in your username and password, and then emulating that request using the WebRequest class.

Once you have done that, the cookie you want should be in the CookieContainer of the WebRequest object. You can then use that cookie in future requests to the site.


AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
That''s the trail that my Usenet searches had led me to follow, but it''s nice to have a confirmation that it''s the right one.

Thank you,

Cédric
It all works now. It turns out that the password was URL-sent, so the sniffer gave me the URL that was sent, and I was able to log in directly.

However, the cookie part didn''t go so well. The loging-in brought me through 3 different web-pages (automatic transitions). And the cookie that I needed wasn''t there once the WebRequest returned. So I had to go through the 3 pages with three different requests. Even with that, the cookie was still not in my CookieContainers. I had to check the headers. I don''t know why .Net didn''t pick it up, but it works now.

Thanks!

Cédric

This topic is closed to new replies.

Advertisement