Schuyler
Schuyler

Reputation: 11

C# WebRequest While staying logged in

I am trying to use a C# webrequest to GET data from a page, then POST data back to the site. The problem I am having however, is that it is logging out between the functions. I have a function that grabs part of the page, and then ends it's request. Then, another function, using that data, logs into the site. After this, another function is made that navigates to another page, and posts data. However, the user is no longer logged in when I attempt to run this final function. What needs to be done so that the user stays logged in?

Thanks

Upvotes: 1

Views: 830

Answers (2)

Timbo
Timbo

Reputation: 4533

The trouble you're having is that after the login a cookie is being set by the website to keep you logged in (whether by session or cookie authentication). To maintain these cookies between the requests / responses you need to use a cookie container. Some details of that implementation can be found on the answer to this question.

Upvotes: 1

Simen S
Simen S

Reputation: 3205

Have you set

 webRequest.PreAuthenticate = True

Upvotes: 1

Related Questions