cookie-based authentication with HttpWebRequest

G

Guest

Providing authentication for protected content via Basic/Digest Headers seems
pretty straight-forward, but I'm stuck trying to figure out how to do
something a little different:

say you have some sort of page of customizable content - an example might be
a portal page that you've tweaked to display your favorite headline topics,
your stock portfolio, etc. The page itself isn't protected so you won't be
challenged when you hit that site, but there's a cookie that must be
available to the server so that every time you visit the site (assuming
you've selected the nefarious 'remember me' option), you don't see the
generic page, but your own version instead.

What does that transaction look like, and how/where would your usename and
password be provided so that you can fetch the right version of the page with
a HTTPWebRequest in C#? I have access to the credentials, I just don't know
where to provide them.

Thanks in advance!

- (more) Cowbell
 
J

Joerg Jooss

Thus wrote cowbell,
Providing authentication for protected content via Basic/Digest
Headers seems pretty straight-forward, but I'm stuck trying to figure
out how to do something a little different:

say you have some sort of page of customizable content - an example
might be a portal page that you've tweaked to display your favorite
headline topics, your stock portfolio, etc. The page itself isn't
protected so you won't be challenged when you hit that site, but
there's a cookie that must be available to the server so that every
time you visit the site (assuming you've selected the nefarious
'remember me' option), you don't see the generic page, but your own
version instead.

What does that transaction look like, and how/where would your usename
and password be provided so that you can fetch the right version of
the page with a HTTPWebRequest in C#? I have access to the
credentials, I just don't know where to provide them.

Thanks in advance!

The best approach to understand how a web applicaton works and how to control
it remotely with HttpWebRequest is to track a browser-based session using
a debugging proxy like Fiddler and then program a sequence of HttpWebRequests
accordingly.

If you have already a persistent cookie on disk, you may even get away with
an unmanaged call to InternetGetCookie(), and add it to your HttpWebRequest's
CookieContainer.

Cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top