47

I am having issues with Visual Studio 2013 and our corporate proxy (signin does not work, updates do not work, visual studio gallery does not work, nuget and git fail ). All of these are doing http or https requests. (e.g. http://visualstudiogallery.msdn.microsoft.com/ ). In VS2013 I just get spinning progress bars or messages about no network connection.

No problem with the browser, (chrome, IE, firefox) since they all understand proxies (407 rejections and then responding with credentials).

So I want to figure out why VS2013 does not work. But I cannot see any traffic when I tell fiddler2 to watch the DEVENV.EXE process (or all processes).

BTW, I have tried some changes to the web.config (devenv.exe.config) file to make sure it goes to the proxy (I saw this in stack builder) but it is not working for me. See the additions to the section below:

    <system.net>
                <defaultProxy useDefaultCredentials="true" enabled="true">
                 <proxy proxyaddress="http://gw6.OURSITE.com:3128" />
                </defaultProxy>
      <settings>
        <ipv6 enabled="true"/>
        <servicePointManager expect100Continue="false" />
       </settings>
    </system.net>

Update

Eric, I took your suggestion and just stuffed it into the C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe.config file.

What I put in was:

  <system.net>
    <defaultProxy useDefaultCredentials="true" enabled="true">
      <proxy autoDetect="false" bypassonlocal="false" proxyaddress="http://127.0.0.1:8888" usesystemdefault="false" />
    </defaultProxy>
  </system.net>

What I found was that VS2013 is not sending a user-agent string. It does know about #407 naks and it replies with credentials, but the gateway still wants a user agent:

HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Type: text/html; charset=utf-8
Proxy-Connection: close
Connection: close
Content-Length: 1341

<html>
    <head>
        <title>Access Policy Denied: No User-Agent Specified</title>
        <meta name="description" content="Web Access Policy">
    </head>
    <body>
user247702
  • 23,641
  • 15
  • 110
  • 157
Dr.YSG
  • 7,171
  • 22
  • 81
  • 139
  • But my issue is not about programs run with Visual Studio as a (DEBUG, etc) with an VS2014. I am running VS2014 as under my account (not a job started by VS). The problem are with VisualStudio itself (it needs to do GIT, NUGET, Sign-IN etc.) all going to microsoft sites. But I can't see which ones are blocked here. – Dr.YSG Jan 15 '14 at 19:44
  • Sounds plausible. I looked at C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config and found the section and is not yet there. But what I did note above is that changing the web.config (devenv.exe.config) for VS2013 itself should have forced VS to go to fiddler. I was surprised it did not. I will test out both and report back (but I am headed out for a vacation so it might have to wait). – Dr.YSG Jan 16 '14 at 21:23
  • Can you put your answer down as a seperate post, so that I can star it and give you credit for solving this issue? – Dr.YSG Jan 17 '14 at 16:48

3 Answers3

42

If you want to look at the traffic with Fiddler, you probably want to go the route of changing the machine.config file so that all .NET applications will send traffic through Fiddler. This helps ensure that you capture data from processes running in services, etc.

Open machine.config in the folder C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config. Note that if you are debugging a 64bit service (like ASP.NET) you will want to look in the Framework64 folder instead of the Framework folder. Similarly, if you are using a .NET version prior to 4.0, you will need to adjust the version part of the path.

Add the following XML block as a peer to the existing system.net element, replacing any existing defaultProxy element if present:

<!-- The following section is to force use of Fiddler for all applications, including those running in service accounts -->
 <system.net>
 <defaultProxy
                 enabled = "true"
                 useDefaultCredentials = "true">
 <proxy autoDetect="false" bypassonlocal="false" proxyaddress="http://127.0.0.1:8888" usesystemdefault="false" />
 </defaultProxy>
 </system.net>

Ref http://fiddler2.com/blog/blog/2013/01/08/capturing-traffic-from-.net-services-with-fiddler

Note: You can use Fiddler to inject a User-Agent header on outbound requests if you like. Also, in the latest version of Fiddler, you can File > Import > Packet Capture to collect HTTP traffic out of .cap files captured using Microsoft NetMon or Microsoft Message Analyzer.

EricLaw
  • 56,563
  • 7
  • 151
  • 196
  • 1
    Super helpful, thanks Eric. I can confirm this works successfully with Charles proxy as well. – lux May 28 '14 at 17:05
  • Can't expect any more than a response from the creator! – Ben Power Jun 11 '14 at 05:55
  • Sorry for the slightly tangential comment, but I had a similar problem and installed Fiddler4 to sniff the comms. Then I noticed that just having Fiddler4 running (I didn't touch anything in the Fiddler UI) was enough for Visual Studio to suddenly be able to communicate via our corporate proxy. As soon as I stopped Fidder, VS could no longer communicate. What might cause that? – Mykro Jan 08 '15 at 02:33
  • 1
    I'd like to add I had an issue with Visual Studio + Resharper, and the licensing not working properly. Be careful if you make this change, and then change the port in Fiddler. You will be faced with the issue where the Resharper license server (in this example) won't be resolved. Obviously this is due to having mis-matched proxy information, but just something for people to be aware of. I forgot I had made this change, and it burned me for 2 weeks! – askrich Aug 25 '15 at 07:46
  • 2
    My **machine.config** file doesn't have a single instance of ``. Could it be that a more recent version of the framework had a schema update? (I _do_ see that node in the **web.config** which is in the same directory as the **machine.config** file). Am I missing something? – Sergey Nov 11 '15 at 19:40
  • @Sergey: `machine.config` still supports the `system.net` section in all versions of the .NET framework. If you don't have a section, you can add it. – EricLaw Nov 12 '15 at 13:41
  • 1
    @EricLaw where should we add `` in `machine.config`? Should it be a child of ``? – Josh Noe Apr 04 '19 at 18:53
  • 1
    Don't forget to remove the element when you don't need the Fidller anymore. Without it the VS can be really buggy (trying to connect to non-existing proxy). – Gh61 Feb 17 '20 at 08:51
13

My boss suggested another easy way to solve this problem. You can just add "fiddler" in the the uri. For example: http://localhost:52101/ --> http://localhost.fiddler:52101/

Pritam De
  • 151
  • 1
  • 4
  • 1
    That's a good idea, however it is not working for me: I am getting HTTP Error 401.1 - Unauthorized after entering the credentials in the IE credential popup dialog. After refreshing the site, I am getting "[Fiddler] The connection to 'localhost' failed. Error: ConnectionRefused (0x274d). System.Net.Sockets.SocketException No connection could be made because the target machine actively refused it 127.0.0.1:4453 ". When running the website directly through visual studio, the credential popup does not appear. Can you help? – Matt Jun 25 '15 at 09:10
  • Worked for me. Thanks! – Alireza Nov 30 '15 at 03:04
  • I can add a "worked for me" also. Nice and quick solution. – Dan Aug 01 '17 at 09:53
9

Alternatively you can use lightweight way like;

if (Debugger.IsAttached) { request.Proxy = new WebProxy("http://localhost:8888/", true); }

Teoman shipahi
  • 47,454
  • 15
  • 134
  • 158
  • what is WebProxy ? is it any class in dotnet ? i try to find this class when working with VS2013 but no luck. – Mou Dec 21 '16 at 13:58