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("http://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>
Comments (17)

  1. Sam Naseri says:

    Hi, I tried this solution but it does not worked for me, can you please explain it more? if the proxy has a port is it alright to write the url as proxyserver.com:8000????

  2. Patrick Belfio says:

    Yes, it work fine, with VS2012

    thanks

  3. Sanhao says:

    it dont work fine with VS2013.

    VS had abnormal end after VS started up.

  4. Olen Salaista says:

    Awesome fix for VS 2013 Community … thanks!!!

  5. Terry Olsen says:

    Can confirm. Worked for VS 2013 Community. Thanks tons!

  6. Narotham Kalluri says:

    Thank you. Working with VS 2015 too.

  7. Stephane Ndong-Mef says:

    I cannot use C++ so a little help would be nice. After creating a DLL project in visual studio, i copy/pasted the code, but I get: "System is undefined".

    missing header? anything else? help please.

  8. Leonardo Sancho says:

    This method worked on VS 2013 Community, thanks!

  9. Chris Larabell says:

    @Stephane Ndong-Mef – This is a C# project, so create a new library project using that language.

  10. lyman12 says:

    Example for VS 2010:

    File – New project – Visual C# – Class Library (.Net Framework 3.5)

    Name: Rido.AuthProxy

    using System;

    using System.Net;

    namespace Rido.AuthProxy

    {

       public class AuthProxyModule : IWebProxy

       {

           ICredentials crendential = System.Net.CredentialCache.DefaultCredentials;

           public ICredentials Credentials

           {

               get

               {

                   return crendential;

               }

               set

               {

                   crendential = value;

               }

           }

           public Uri GetProxy(Uri destination)

           {

               return new Uri("http://proxy:port/&quot;, UriKind.Absolute);

           }

           public bool IsBypassed(Uri host)

           {

               return host.IsLoopback;

           }

       }

    }

    1. ess pr says:

      Can you please tell how to make it work for VS2015 community?

      1. Rido says:

        There is no differences using VS2015 community, pro or enterprise. What problem do you have?

  11. md says:

    Thanks! Worked with VS2015 community RC!

  12. Ignacio Soler says:

    It is working (at least I can connect to TFS) but I cannot authenticate to TFS. It always says that the password  is wrong. Any ideas?

  13. Tamer says:

    Hi,

    it's not working for me VS 2013

  14. Gilbert says:

    Cant get it to work. VS crashes. The solution offered by MS (editing an XML file) fails. This too.
    It is amazing that in 2016 Microsoft ignores that most companies are using, for security purposes, filters to Internet, where a proxy authentication is required.

    I have dozens of applications installed on my laptop. Most have a switch I can activate, and three fields to enter the proxy IP, port, login and password.

    If independant authors are capable of making this work easily, why can’t Microsoft too ?

    The most amazing thing being this problem has been known since the beta of VS 2015. Microsoft was told about it. The VS 2015 went into production and release. Patches went by, and this is still a problem.

    Next time someone in the company talks about using a Microsoft tool or solution, I will tell them this story and we will select another seller. We are ditching C# for Java as of now, because Microsoft does not listen to people giving them money.

  15. Rodrigo says:

    Worked with VS 2015 community with update 2!!!