5

The "WebClient" class (and ClickOnce also) can use default proxy settings (e.g. put in application.config), however:

  1. Where does the username / password come from? (I can't see a setting in the XML config - see below).
  2. Can the application be configured to manual prompt the user for the username/password

http://msdn.microsoft.com/en-us/library/kd3cf2ex.aspx

<defaultProxy
enabled="true|false"
useDefaultCredentials="true|false"
<bypasslist> … </bypasslist>
<proxy> … </proxy>
<module> … </module>
/>

PS. I've just been testing with the following below setup and confirmed that the Username/Password does not come from a successful logged on IE session.

Outstanding question is therefore where would the username/password come from? Or does it have to be programmatically supplied within the custom application, in which case what happens with ClickOnce then? (which doesn't seem to launch any dialog to allow a user to supply the username/password)

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.net>
      <defaultProxy enabled="true" useDefaultCredentials="false">
        <bypasslist>
          <add address="localhost" />
        </bypasslist>
        <proxy usesystemdefault="True" proxyaddress="http://proxy1.health.qld.gov.au:80/" bypassonlocal="False" />
      </defaultProxy>
    </system.net>
</configuration>



private void button2_Click(object sender, EventArgs e)
{
    Cursor.Current = Cursors.WaitCursor;
    try
    {
        var wc = new WebClient();
        var str = wc.DownloadString(textBox1.Text);
        MessageBox.Show("String = " + str);
    } 
    finally
    {
        Cursor.Current = Cursors.Default;

    }
}
Greg
  • 34,042
  • 79
  • 253
  • 454

2 Answers2

2

The credentials come from your network settings. You can easily set them manually in code, simply use the WebProxy class.

WebProxy proxy = new WebProxy("http://yourproxyserveraddress");
NetworkCredential cred = new NetworkCredential("user","password","domain");
proxy.Credentials = cred;
HttpWebRequest.DefaultWebProxy = proxy;
Tim Jarvis
  • 18,465
  • 9
  • 55
  • 92
  • thanks - can I also ask where they would come from in the case of clickonce when it is not my application that is accessing them? So I guess the question is what do you mean by Network Settings? Is this the windows login? (issue I have re clickonce is that the proxy server configuration/credentials for the company are separate to any other credentials used) – Greg Mar 10 '10 at 04:37
  • I'm not sure what you mean in the case of ClickOnce, the issue/settings are the same whoever is executing code that access's the i/net. You will find your proxy settings in the Internet connections dialog, easiest way to find it is via GodMode (google it) if you have windows 7 or Vista or from Internet Explorer Tools->Internet Options. – Tim Jarvis Mar 10 '10 at 07:09
  • But these settings don't include username/password do they? Ie I'm not sure how to set username/password for oneclick (but perhaps this warrents a separate question) – Greg Mar 10 '10 at 09:00
0

If you don't add any NetworkCredential, the credentials come from the Identity that is setup in your Application Pool.

Open IIS Manager --> Application Pools

Case 1:

If your Web app is under an App pool whose Identity is Built-in account i.e. ApplicationPoolIdentity:

--> This will use IIS APPPOOL\MEILIAPPPOOL account.

Case 2:

You can setup the App pool with some service account, like this:

--> This will use DOMAIN\SERVICEACCOUNTUSERNAME account.

Ash K
  • 1,802
  • 17
  • 44