当使用“默认代理”时用户名/密码从哪里来?

发布于 2024-08-24 17:12:31 字数 1505 浏览 5 评论 0原文

“WebClient”类(还有 ClickOnce)可以使用默认代理设置(例如放入 application.config 中),但是:

  1. 用户名/密码来自哪里? (我看不到 XML 配置中的设置 - 见下文)。
  2. 是否可以将应用程序配置为手动提示用户输入用户名/密码

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

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

PS。我刚刚使用以下设置进行了测试,并确认用户名/密码不是来自成功登录 IE 会话。

因此,悬而未决的问题是用户名/密码从哪里来?或者是否必须在自定义应用程序中以编程方式提供,在这种情况下 ClickOnce 会发生什么? (这似乎没有启动任何对话框来允许用户提供用户名/密码)

<?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;

    }
}

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;

    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

何其悲哀 2024-08-31 17:12:31

凭据来自您的网络设置。您可以轻松地在代码中手动设置它们,只需使用 WebProxy 类即可。

WebProxy proxy = new WebProxy("http://yourproxyserveraddress");
NetworkCredential cred = new NetworkCredential("user","password","domain");
proxy.Credentials = cred;
HttpWebRequest.DefaultWebProxy = proxy;

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;
夏末 2024-08-31 17:12:31

如果您不添加任何NetworkCredential,则凭据来自应用程序池中设置的身份。

打开IIS管理器-->应用程序池

案例 1:

如果您的 Web 应用程序位于其身份为内置帐户(即 ApplicationPoolIdentity)的应用程序池下:

-->这将使用 IIS APPPOOL\MEILIAPPPOOL 帐户。

情况 2:

您可以使用某些服务帐户设置应用程序池,如下所示:

-->这将使用 DOMAIN\SERVICEACCOUNTUSERNAME 帐户。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文