WPF XAML图像源和所需的windows身份验证

本文关键字:windows 身份验证 XAML 图像 WPF | 更新日期: 2023-09-27 18:25:18

我想显示来自需要windows身份验证的网站的图像。我目前正在使用这个:

<Image Grid.Column="0" Source="https://Foo/899fddb8-d5df-4f04-9d20-50de22f7d671/0102d4d6-3c3d-4717-985b-74021348413d.png" Margin="5,0,0,0" />

它在浏览器上工作,这个代码工作:

<Image Grid.Column="0" Source="http://img.clubic.com/00C8009607654557-c1-photo-bbpppremium.jpg" Margin="5,0,0,0" />

WPF XAML图像源和所需的windows身份验证

我找到了解决方案:

在我的App.config中,我放了:

  <system.net>
    <defaultProxy enabled="true" useDefaultCredentials="true"  />
  </system.net>

在我的应用程序类中:

public partial class App : Application
{
    public App()
    {
        Current.Startup += CurrentOnStartup;
    }
    private void CurrentOnStartup(object sender, StartupEventArgs startupEventArgs)
    {
        WebRequest.DefaultWebProxy.Credentials = CredentialCache.DefaultNetworkCredentials;
        AuthenticationManager.CredentialPolicy = new ProxyCredentials();
    }
}
internal class ProxyCredentials : ICredentialPolicy
{
    bool ICredentialPolicy.ShouldSendCredential(Uri challengeUri, WebRequest request, NetworkCredential credential,
        IAuthenticationModule authenticationModule)
    {
        return true;
    }
}

来源:http://social.msdn.microsoft.com/Forums/vstudio/en-US/e5a064eb-578b-4334-95f6-e40d5a0e2cc2/proxy-authentication-problems-with-remote-resources-error-407?forum=wpf