How to connect to TFS through authenticated Web Proxy

Today I was in a customer where the internet access is provided by a WebProxy that requires credentials.

For some reason, although VS can navigate, the Team Explorer was not able to connect to our TFS server, because a 407 error (Proxy authentication required)

To fix this issue you need a custom proxy module that provides the credentials, so I created a simple DLL with this class:

 

 using System;
 using System.Net;
  
 namespace Rido.AuthProxy
 {
     public class AuthProxyModule : IWebProxy
     {
  
         ICredentials crendential = new NetworkCredential("proxy.user", "password");
  
         public ICredentials Credentials
         {
             get
             {
                 return crendential;
             }
             set
             {
                 crendential = value;
             }
         }
  
         public Uri GetProxy(Uri destination)
         {
             return new Uri("https://proxy:8080", UriKind.Absolute);
         }
  
         public bool IsBypassed(Uri host)
         {
             return host.IsLoopback;
         }
  
     }
 }

You should copy this DLL to the %PROGRAMFILES\Microsoft Visual Studio 10.0\Common7\IDE folder, and update the devenv.exe.config file to include the module:

 <system.net>
     <defaultProxy>
       <module type="Rido.AuthProxy.AuthProxyModule, Rido.AuthProxy"/>
     </defaultProxy>
   </system.net>