Hi all,

How do I determine if IE is configured to use a proxy server? If IE is
configured to use a proxy server, then how do I get a WebProxy object
equivalent to the HTTP proxy server that IE is configured to use?

In the registry, HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet
Settings contains keys that appear to tell me if IE is configured to use a
proxy server, and, if so, the URL of the proxy server. I'm just not sure if
reading the registry is the "correct" way to get these values, or if there
is some .Net function that gets me this information in a more supported way.

TIA,

- Bob

Re: How to fetch the default HTTP proxy by Joerg

Joerg
Sat Jun 12 03:56:13 CDT 2004

Bob Altman wrote:
> Hi all,
>
> How do I determine if IE is configured to use a proxy server? If IE
> is configured to use a proxy server, then how do I get a WebProxy
> object equivalent to the HTTP proxy server that IE is configured to
> use?
>
> In the registry,
> HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings
> contains keys that appear to tell me if IE is configured to use a
> proxy server, and, if so, the URL of the proxy server. I'm just not
> sure if reading the registry is the "correct" way to get these
> values, or if there is some .Net function that gets me this
> information in a more supported way.

There's no need to peek into the registry; System.Net.GlobalProxySelection
comes to the rescue ;-)


IWebProxy systemProxy = GlobalProxySelection.Select; // Property, not a
method!

Cheers,

--
Joerg Jooss
joerg.jooss@gmx.net


Re: How to fetch the default HTTP proxy by Bob

Bob
Sat Jun 12 10:50:40 CDT 2004

That doesn't seem to work for me. The proxy that I get back from

systemProxy = GlobalProxySelection.Select

is "empty" (its Address property is blank). According to the docs, "the
default proxy setting is initialized from the global or application config
file".

- Bob

"Joerg Jooss" <joerg.jooss@gmx.net> wrote in message
news:%23n6SXsFUEHA.712@TK2MSFTNGP11.phx.gbl...
> Bob Altman wrote:
> > Hi all,
> >
> > How do I determine if IE is configured to use a proxy server? If IE
> > is configured to use a proxy server, then how do I get a WebProxy
> > object equivalent to the HTTP proxy server that IE is configured to
> > use?
> >
> > In the registry,
> > HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings
> > contains keys that appear to tell me if IE is configured to use a
> > proxy server, and, if so, the URL of the proxy server. I'm just not
> > sure if reading the registry is the "correct" way to get these
> > values, or if there is some .Net function that gets me this
> > information in a more supported way.
>
> There's no need to peek into the registry; System.Net.GlobalProxySelection
> comes to the rescue ;-)
>
>
> IWebProxy systemProxy = GlobalProxySelection.Select; // Property, not a
> method!
>
> Cheers,
>
> --
> Joerg Jooss
> joerg.jooss@gmx.net
>



Re: How to fetch the default HTTP proxy by Joerg

Joerg
Sat Jun 12 12:52:10 CDT 2004

Bob Altman wrote:
> That doesn't seem to work for me. The proxy that I get back from
>
> systemProxy = GlobalProxySelection.Select
>
> is "empty" (its Address property is blank). According to the docs,
> "the default proxy setting is initialized from the global or
> application config file".

Sorry, I got confused. If do not set a specific proxy and your
machine.config specifies

<defaultProxy>
<proxy usesystemdefault="true"/>
</defaultProxy>

(that's the default configuration), HttpWebRequest will use the operating
system's proxy setting. Unfortunately, GlobalPrxySelection.Select does *not*
return an appropriate IWebProxy in this case. So the answer is
a) don't do anything in order to use the system's default proxy, assuming
you're running the default configuration;
b) unfortunately, there seems to be no "easy" API that retrieves it as in
IWebProxy instance.

Cheers,


--
Joerg Jooss
joerg.jooss@gmx.net


Re: How to fetch the default HTTP proxy by Bob

Bob
Sat Jun 12 13:21:26 CDT 2004

Sorry, you lost me there... What do you mean "don't do anything in order to
use the system's default proxy, assuming you're running the default
configuration"? My computer is set up to use a proxy server. However, if I
don't go out of my way to feed the URL of my proxy server to the WebRequest,
then it fails when it tries to contact the remote website.

- Bob

"Joerg Jooss" <joerg.jooss@gmx.net> wrote in message
news:%23gNC2XKUEHA.228@TK2MSFTNGP10.phx.gbl...
> Bob Altman wrote:
> > That doesn't seem to work for me. The proxy that I get back from
> >
> > systemProxy = GlobalProxySelection.Select
> >
> > is "empty" (its Address property is blank). According to the docs,
> > "the default proxy setting is initialized from the global or
> > application config file".
>
> Sorry, I got confused. If do not set a specific proxy and your
> machine.config specifies
>
> <defaultProxy>
> <proxy usesystemdefault="true"/>
> </defaultProxy>
>
> (that's the default configuration), HttpWebRequest will use the operating
> system's proxy setting. Unfortunately, GlobalPrxySelection.Select does
*not*
> return an appropriate IWebProxy in this case. So the answer is
> a) don't do anything in order to use the system's default proxy, assuming
> you're running the default configuration;
> b) unfortunately, there seems to be no "easy" API that retrieves it as in
> IWebProxy instance.
>
> Cheers,
>
>
> --
> Joerg Jooss
> joerg.jooss@gmx.net
>



Re: How to fetch the default HTTP proxy by Joerg

Joerg
Sat Jun 12 17:19:07 CDT 2004

Bob Altman wrote:
> Sorry, you lost me there... What do you mean "don't do anything in
> order to use the system's default proxy, assuming you're running the
> default configuration"?

Assuming you're running the default .NET configuration (i.e. you didn't
modify the proxy settings in machine.config), you don't need to assign an
IWebProxy instance to your HttpWebRequest's proxy property.

> My computer is set up to use a proxy server.
> However, if I don't go out of my way to feed the URL of my proxy
> server to the WebRequest, then it fails when it tries to contact the
> remote website.

Works for me. Does your proxy use authentication?

Cheers,

--
Joerg Jooss
joerg.jooss@gmx.net


Re: How to fetch the default HTTP proxy by Bob

Bob
Mon Jun 14 18:20:08 CDT 2004

>Does your proxy use authentication?

I don't know... how would I tell? In order to get through my corporate
firewall, all I need to do is specify the proxy address and port. I don't
see anything about "authentication" on the dialogs that I get to by going to
Internet Properties, Connections tab, LAN Settings button, Advanced button.

Just to make sure we're on the same page, here is the code I'm using:

Imports System.Net

' This is required to get through my corporate proxy server
Dim proxy As New WebProxy(http://my-proxy.xyz.com:80)
GlobalProxySelection.Select = proxy

Dim url As String = "http://www.somewhere.com/main.html"
dim wr as HttpWebRequest = DirectCast(WebRequest.Create(url),
HttpWebRequest)
With wr
' Set credentials to use for this request
.Credentials = CredentialCache.DefaultCredentials

' Get the response from the website
Dim response As HttpWebResponse = DirectCast(.GetResponse(),
HttpWebResponse)

... etc...
End With



Re: How to fetch the default HTTP proxy by v-phuang

v-phuang
Mon Jun 14 22:10:22 CDT 2004

Hi Bob,

I agree with Joerg's suggestion.
<proxy> Element
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/ht
ml/gngrfproxyelement.asp

The <proxy> element defines a proxy server for an application. When the
usesystemdefault attribute is true, the application uses the proxy defined
in the Internet Options dialog box.

If we define the usesystemdefault in the proxy element we do not need to
specified the proxy in our code. That is to say we can use the
httpwebrequest just as we access the website directly.

If we use a authentication proxy in internet explorer, usually a dialog
will be pop up which ask for authentication information used to access the
proxy.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.


Re: How to fetch the default HTTP proxy by Bob

Bob
Tue Jun 15 14:52:03 CDT 2004

Hmmm... curious. My machine.config file has not been modified, and it
contains

<defaultProxy>
<proxy usesystemdefault="true"/>

And yet my application doesn't work unless I create a WebProxy object and
provide it as the value of the GlobalProxySelection.Select property.

Do I need to do something to tell .Net to use the settings in
machine.config?

- Bob



Re: How to fetch the default HTTP proxy by feroze

feroze
Wed Jun 16 00:14:15 CDT 2004

Here are the rules for proxy behavior in System.Net:

1) The appdomain setting overrides the machine.config/app.config settings.
2) The per-request proxy (set using httpwebrequest.Proxy) overrides #1

Do you want to do authentication for proxy ? If so, set the credential on
the proxy, not the webrequest.

proxy.Credentials = new NetworkCredential("proxyuser", "proxypass",
"proxydomain");

--

Thanks

feroze
=============
This posting is offered as-is. It offers no warranties and confers no
rights.

"Bob Altman" <rda@nospam.com> wrote in message
news:eaeD8IxUEHA.2388@TK2MSFTNGP09.phx.gbl...
> Hmmm... curious. My machine.config file has not been modified, and it
> contains
>
> <defaultProxy>
> <proxy usesystemdefault="true"/>
>
> And yet my application doesn't work unless I create a WebProxy object and
> provide it as the value of the GlobalProxySelection.Select property.
>
> Do I need to do something to tell .Net to use the settings in
> machine.config?
>
> - Bob
>
>



Re: How to fetch the default HTTP proxy by Bob

Bob
Wed Jun 16 13:23:36 CDT 2004

Sorry, I'm missing something really fundamental here...

I apparently don't need to do authentication. (The authentication stuff in
my original example was just copied-and-pasted from the example in the MSDN
docs.) If I remove all references to Credentials, my code still works as
before. As near as I can tell, the minimum code that I need to access a
website in code is:

' These two lines are necessary to get through the firewall
Dim proxy As New WebProxy("<My proxy name:8080>")
GlobalProxySelection.Select = proxy

Dim url As String = "<desired website>"
Dim wr As HttpWebRequest = DirectCast(WebRequest.Create(url),
HttpWebRequest)
dim response as HttpWebResponse = DirectCast(wr.GetResponse(),
HttpWebResponse)

I just don't want to hard-code my proxy address in my code. But if I remove
the first two code lines, the call to GetResponse fails.

As another attempt to get this to work, I created an app.config file and put
the following into it:

<?xml version="1.0" encoding="utf-8" ?><configuration>
<configuration>
<system.net>
<defaultProxy>
<proxy usesystemdefault="true" />
</defaultProxy>
</system.net>
</configuration>

Then I removed the GlobalProxySelection stuff and tried it. Still doesn't
work.



Re: How to fetch the default HTTP proxy by v-phuang

v-phuang
Wed Jun 16 20:18:46 CDT 2004

Hi Bob,

I think you may try to run your code on another machine without using
WebProxy and set the <proxy usesystemdefault="true" /> in the
machine.config in that test machine to see if the problem persists, this
will help us isolate the problem.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.


Re: How to fetch the default HTTP proxy by Bob

Bob
Thu Jun 17 12:05:45 CDT 2004

Peter,

I'm going to give up on this issue for now... If and when I need to
understand what is going on, I'll burn an MSDN telephone incident.

Many thanks to all for helping me get something of a handle on this issue
(even if I never did get it work properly ;-)

- Bob



Re: How to fetch the default HTTP proxy by Ross

Ross
Fri Jun 18 09:05:11 CDT 2004

Hi Bob,

Did you try WebProxy.GetDefaultProxy() ? The GetDefaultProxy method reads
the nondynamic proxy settings stored by Internet Explorer and creates a
WebProxy instance with those settings.

--
Ross Donald
Rad Software
Free Regular Expression Designer @
http://www.radsoftware.com.au/web/Products/


"Bob Altman" <rda@nospam.com> wrote in message
news:uhIS4RAUEHA.972@TK2MSFTNGP10.phx.gbl...
| Hi all,
|
| How do I determine if IE is configured to use a proxy server? If IE is
| configured to use a proxy server, then how do I get a WebProxy object
| equivalent to the HTTP proxy server that IE is configured to use?
|
| In the registry, HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet
| Settings contains keys that appear to tell me if IE is configured to use a
| proxy server, and, if so, the URL of the proxy server. I'm just not sure
if
| reading the registry is the "correct" way to get these values, or if there
| is some .Net function that gets me this information in a more supported
way.
|
| TIA,
|
| - Bob
|
|



Re: How to fetch the default HTTP proxy by Bob

Bob
Tue Jun 22 17:50:52 CDT 2004

Ross,

There must be something seriously strange about the way my PC is set up
(although I'll be darned if I can see what it is). WebProxy.GetDefaultProxy
returns an "empty" Proxy (its .Address property is Nothing) identical to the
proxy I get from GlobalProxySelection.Select(). As I said on the other
branch of this conversational thread, I'm giving up for now. If this really
becomes a practical problem (as opposed to an intellectual curiosity, as it
is now), I'll burn an MSDN incident to get it figured out.

BTW, I downloaded the regular expression designer in your signature line.
Whenever I work with regex, I invariably wind up writing a small test
program to fiddle around with the regex syntax and to try to wrap my brain
around the resultant regex objects (matches, captures, etc.). This is just
the tool I've needed (but didn't realize I needed). Thanks!

- Bob

"Ross Donald" <ross@radsoftware.com.auNOSPAM> wrote in message
news:umvvT1TVEHA.3944@tk2msftngp13.phx.gbl...
> Hi Bob,
>
> Did you try WebProxy.GetDefaultProxy() ? The GetDefaultProxy method reads
> the nondynamic proxy settings stored by Internet Explorer and creates a
> WebProxy instance with those settings.
>
> --
> Ross Donald
> Rad Software
> Free Regular Expression Designer @
> http://www.radsoftware.com.au/web/Products/



Re: How to fetch the default HTTP proxy by Joerg

Joerg
Sat Jun 26 03:16:24 CDT 2004

Ross Donald wrote:
> Hi Bob,
>
> Did you try WebProxy.GetDefaultProxy() ? The GetDefaultProxy method
> reads the nondynamic proxy settings stored by Internet Explorer and
> creates a WebProxy instance with those settings.

Ah... that's the method I was missing in my earlier post. Microsoft, please
move this method to GlobalProxySelection, I really don't see why proxy
retrieval should be scattered all over the BCL.

Cheers,

--
Joerg Jooss
joerg.jooss@gmx.net