2014-10-01 42 views
0

我想要顯示來自需要Windows身份驗證的網站的圖像。我目前使用這樣的:WPF XAML Image Source和所需的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" /> 

回答

1

我找到了解決辦法:

在我的App.config中我把:

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

在我的App類中:

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