Home
Manage Your Code
Snippet: Using IE Proxy in .NET (C#)
Title: Using IE Proxy in .NET Language: C#
Description: Using the IE/System proxy in .NET (http://www.fiddler2.com/fiddler/help/hookup.asp#Q-DOTNET) Views: 1203
Author: Stephen Smith Date Added: 11/2/2011
Copy Code  
1Configure a .NET application to use Fiddler?
2If you're coding a .NET application, K Scott Allen's blog shows a simple way to hook Fiddler temporarily for debugging purposes:
3
4GlobalProxySelection.Select = new WebProxy("127.0.0.1", 8888);
5
6Note that you might not even need to do this-- The Framework should autodetect the WinINET proxy when the .NET application starts.  Note that this means that Fiddler must be started BEFORE your application if your application is to autodetect Fiddler.
7
8You may specify a proxy inside the yourappname.exe.config file.
9
10<configuration>
11  <system.net>
12    <defaultProxy>
13      <proxy bypassonlocal="false" usesystemdefault="true" />
14    </defaultProxy>
15  </system.net>
16</configuration>
17
18See http://msdn.microsoft.com/en-us/magazine/cc300743.aspx for more on this topic.

19
20Another setting to check is inside machine.config. Ensure the following is present:
21
22<proxy usesystemdefault="true" />
23
24If all else fails, you can manually specify the proxy on an individual WebRequest object, like so:
25
26objRequest = (HttpWebRequest)WebRequest.Create(url);
27objRequest.Proxy= new WebProxy("127.0.0.1", 8888);
28
29Important: Regardless of other settings, .NET will always bypass the Fiddler proxy for URLs containing localhost.  So, rather than using localhost, change your code to refer to the machine name.  For instance:
30
31Does not show in Fiddler: http://localhost/X509SignCodeService/X509SigningService.asmx

32
33Shows in Fiddler: http://mymachine/X509SignCodeService/X509SigningService.asmx
Notes
See form the fiddler help site http://www.fiddler2.com/fiddler/help/hookup.asp#Q-DOTNET