-2

Step 1 : Log into a website Step 2 : navigate a a particular page Step 3 : download a file (I suppose webclient would be ideal here)

would like all this to be happening silently without the user knowing it . I do not want to use the webbrowser object for the same reason

Note : The Website is built by someone else disconnects if the user is idle for a certain period of time.

Problem is , I have no idea reagarding how to go about keeping the user logged in that website using c# . I do not have a concrete idea of it yet . i just wanted someone to point me in the right direction .

Thanks

HelloWorld_Always
  • 1,555
  • 3
  • 22
  • 32
  • Could you provide more detail? What exactly are you trying to accomplish? Is there a specific website you're trying to log in to? Or just in general? Is that a website you've built or someone else's? Once you log in, what do you need to do? – Joel Beckham Jun 09 '11 at 16:42
  • You're not going to get many answers if you don't provide any details at all. We can't read your mind. – Joel Beckham Jun 09 '11 at 17:43
  • i have edited the question .I apologize for not being clear – HelloWorld_Always Jun 09 '11 at 17:49
  • Out of curiosity, what's the desire behind this mechanism? The combination of the phrases "download a file" and "without the user knowing it" could be interpreted as having lurid implications... :) – Dan J Jun 09 '11 at 18:20
  • lol .. Its to simply have users not go inside it and download it. Instead on teh click of a button ,the file could be downloaded in a certain location – HelloWorld_Always Jun 09 '11 at 18:27

1 Answers1

1

Unfortunately, I haven't done this myself, so I can't be much help. Here is a high level overview of how I've seen others do it, so it may give you something to start with.

Use the HttpWebRequest class. You'll need to POST the username and password to the login page (this will really depend on the actual form you're trying to log in to). You'll get a cookie back. You'll need to send the cookie with future requests to keep you logged in. The HttpWebRequest.CookieContainer property may help with this. HttpWebRequest can be used to download the file as well.

Here is an example (see the accepted answer): How to Download the File using HttpWebRequest and HttpWebResponse class(Cookies,Credentials,etc.)

An example of logging in (they were having an issue, but it looks like they figured it out so make sure to read the very last post in the thread for the solution): http://social.msdn.microsoft.com/Forums/en-US/netfxnetcom/thread/f720e70c-6f74-4085-abbe-8e537f0cb390

Another example (see the Accepted Answer): Login to the page with HttpWebRequest

Sorry I can't be more help. Hopefully someone else has some more experience with this.

Community
  • 1
  • 1
Joel Beckham
  • 18,254
  • 3
  • 35
  • 58