Search code examples
c#wpfxamlwindows-authenticationimagesource

WPF XAML Image Source and required windows authentication


I want to display an image from an website requiring windows authentication. I'm currently using this:

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

It works on browser and this code works :

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

Solution

  • I found the solution :

    In my App.config I put :

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

    In my App class :

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

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