WebClient and proxy authentication




I have a windows application that is using the System.Net.WebClient class to
download files requested by the user from a remote server. I am having
problems getting proxy authentication to work correctly.

Essentially I need the application to prompt the user for a username and
password if required for the proxy. I would like to use the windows network
authentication to perform this ( i.e the prompt that you would get in IE when
proxy authentication is required). Is there a way to get the WebClient to
prompt for authentication automatically if required ( I am always using the
default IE proxy).

Simply put:

WebClient client = new WebClient()
client.Proxy.Credentials = CredentialCache.DefaultCredentials;
// the following line will fail when an authenticating proxy
byte[] data = client.DownloadData( "....");



Hi Vadym,

Here's some background info: A user is using IE to browse the internet, and
their proxy requires their credentials before allowing their request through
(an authenticating proxy). So the proxy challenges IE which then prompts the
user for their credentials, also allowing them the option of remembering
their credentials.

This situation is the same in Windows if opening files on file servers, that
is, Windows challenges the user for their credentials, also allowing them the
option of remembering their credentials.

So, if my program uses WebClient to download a file, it will also get the
the un-authenticated error, at which time, the program needs to pop up the
IE/Windows credentials window for the user's credentials.

I can't use the DefaultCredentials, or DefaultNetworkCredentials because
these don't have the correct credentials for the proxy. The credential cache
*also* doesn't have any valid credentials.

In short, the user is logged in on one domain, and the proxy (or even the
fileserver) they're connecting to is on another domain, and they need to
authenticate themselves to that domain.

Hope that makes sense.

This functionality exists in Wininet with the InternetErrorDlg() function.


Peter Huang [MSFT]

Hi Daniel,

I agree with Vadym's suggestion that the Challenge Dialog is pop up by IE
If you would like a similar feature for your scenario, I think you may try
to build a dialog just as Vadym's suggestion.

Anyway, please try Vadym's suggestion, if that still did not work for you.
Can you elaborate more information? I am happy to be of assistance.
e.g. what concrete error message did you get?
What is the Proxy software? How is it do the authenticaion?

Thanks for your efforts!

Best regards,

Peter Huang

Microsoft Online Community Support
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
This posting is provided "AS IS" with no warranties, and confers no rights.

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