webclient object and forms authentication

  • Thread starter Thread starter buran
  • Start date Start date
B

buran

How do I download file from the web when the site uses forms authentication?
Without the authentication, webclient object works.

Thanks,

Buran
 
buran said:
How do I download file from the web when the site uses forms authentication?
Without the authentication, webclient object works.

You have to log in, same as a user would.
 
How can I login using WebClient or WebRequest object? Could you please give
sample code?

Thakn you
 
buran said:
How can I login using WebClient or WebRequest object? Could you please give
sample code?

Not really. The only code I have which does this is embedded in a complex
asynchronous program.

The idea is that you need to POST the username and password just like the
browser does. You will find that a downside is that the browser sends
name/value pairs, where the name is the name of the control to which the
value applies, like username=john. An issue is that in ASP.NET, the name is
likely to be something compound, like _ctl0:_ctl1:username. The numbering of
the _ctln names is likely to change over time as the form is maintained, so
your code will either have to change when the login page changes, or else
try to guess what the names are by looking at the form.

FYI, the way a login sequence usually works in Forms Authentication is:

1. Client requests: GET desiredPage.aspx
2. Server responds with a "302 Page moved" response, giving the location of
the login page:
3. Client requests the login page with a GET
4. Server responds with the login page, which includes the form fields
you'll need to fill in
5. Client sends the username/password with a POST to the login page
6. Server responds with a "302 Page moved" response, giving the location of
desiredPage.aspx and also a login cookie
7. Client requests desiredPage.aspx with a GET, including the login cookie,
and this time it succeeds

I hope this helps, and I'm sorry my code wouldn't help you much.
 
Back
Top