By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,143 Members | 1,855 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,143 IT Pros & Developers. It's quick & easy.

Programmatically add Proxy to web request

P: n/a
Hello

apologies if this is the wrong newsgroup to be sending this to.

Basically, I have an ASP.NET application that I am trying to force to use a
proxy server settings. This can be done by accessing machine.config, but I
do not have access to the client machine.config machine.

Therefore every request made from this application must have these proxy
server settings. But I am having problems writing the code for this.

I have decdided to implement this in a HttpModule.

The code I have is in a custom BeginRequest event within the module. I have
not been able to test it yet, but would this be the correct way to do it:
//************************************************** *********************
WebProxy wp = new WebProxy("http://my.proxy.blah", true);

HttpRequest req = ((HttpApplication)sender).Request;
HttpWebRequest hwr = (HttpWebRequest) WebRequest.Create(req.Url);
hwr.Proxy = wp;
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a

"Codex Twin" <co***@more.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hello

apologies if this is the wrong newsgroup to be sending this to.

Basically, I have an ASP.NET application that I am trying to force to use a proxy server settings. This can be done by accessing machine.config, but I
do not have access to the client machine.config machine.

Therefore every request made from this application must have these proxy
server settings. But I am having problems writing the code for this.

I have decdided to implement this in a HttpModule.

The code I have is in a custom BeginRequest event within the module. I have not been able to test it yet, but would this be the correct way to do it:
//************************************************** *********************
WebProxy wp = new WebProxy("http://my.proxy.blah", true);

HttpRequest req = ((HttpApplication)sender).Request;
HttpWebRequest hwr = (HttpWebRequest) WebRequest.Create(req.Url);
hwr.Proxy = wp;


I think it might be better to supply the full procedure code I have in my
HttpModule:

public void OnBeginRequest(object sender, EventArgs e)
{
WebProxy wp = new WebProxy("http://my.proxy.blah", true);

HttpRequest req = ((HttpApplication)sender).Request;
HttpWebRequest hwr = (HttpWebRequest) WebRequest.Create(req.Url);
hwr.Proxy = wp;
}


Nov 21 '05 #2

P: n/a
As a last ditch, you might want to think about a server side change to
machine.config. If you cannot make your server side code use an .NET
service proxy to access your service, then this is another way to go.There
are some other threads on this board that relate to proxy, and one of them
links to an article that shows how to make every HTTP request originating
in the server (asp.net wise) use a proxy server.

Regards

Dan
--------------------
From: "Codex Twin" <co***@gmail.com>
Newsgroups: microsoft.public.dotnet.framework.webservices
References: <#T**************@TK2MSFTNGP10.phx.gbl>
<#R**************@TK2MSFTNGP15.phx.gbl>
<2o**************@cpmsftngxa10.phx.gbl>
Subject: Re: Programmatically add Proxy to web request
Date: Thu, 2 Dec 2004 21:48:08 -0000
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-RFC2646: Format=Flowed; Original
Lines: 101
Message-ID: <41**********************@ptn-nntp-reader02.plus.net>
Organization: Customer of PlusNet plc (http://www.plus.net)
NNTP-Posting-Host: d1995647.ptn-nntp-reader02.plus.net
X-Trace:
DXC=gg=@M:R=\=W<FQRKCaZH[Xigd3Y`7Rb;^37XnI;[OUCTb3j8L`S>_5[FUllE;002AXDQMPNP
NkEHT:f2H^U1egMQ
X-Complaints-To: ab***@plus.net
Path:
cpmsftngxa10.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFT NGP08.phx.gbl!newsfeed00.s
ul.t-online.de!t-online.de!news.zanker.org!nntp-peering.plus.net!ptn-nntp-fe
eder01.plus.net!ptn-nntp-spool01.plus.net!ptn-nntp-reader02.plus.net!not-for
-mail
Xref: cpmsftngxa10.phx.gbl
microsoft.public.dotnet.framework.webservices:7770
X-Tomcat-NG: microsoft.public.dotnet.framework.webservices

Hi

Sorry, I should have made this clearer. I am dealing with an ASP.NET
webforms application and not a WebService.
I know that the WebService class has a Proxy property.

In my case, I am trying to ensure that every request to the web application
is routed via a proxy server URL.
I know that the HttpWebRequest class has a Proxy property as well but I do
not know how to use it. My thinking has been to try and intercept each
request within an HttpModule, but at that point I am stuck.

Thanks
"Dan Rogers" <da***@microsoft.com> wrote in message
news:2o**************@cpmsftngxa10.phx.gbl...
Hi,

There, I think, is a far simpler approach. The proxy that you generated
from an add-web-reference operation, in your client code, supports HTTP
proxies natively. Check out the Proxy property on that generated service
proxy. You can create a WebProxy instance, using your named proxy, and
set
that on your service proxy. This makes the service proxy direct its
requests thru your web proxy.

I hope this helps

Dan Rogers
Microsoft Corporation
--------------------
From: "Codex Twin" <co***@more.com>
References: <#T**************@TK2MSFTNGP10.phx.gbl>
Subject: Re: Programmatically add Proxy to web request
Date: Thu, 2 Dec 2004 19:01:18 -0000
Lines: 46
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
Message-ID: <#R**************@TK2MSFTNGP15.phx.gbl>
Newsgroups: microsoft.public.dotnet.framework.webservices
NNTP-Posting-Host: 193.115.152.15
Path:
cpmsftngxa10.phx.gbl!TK2MSFTFEED01.phx.gbl!TK2MSFT NGP08.phx.gbl!TK2MSFTNGP15 phx.gbl
Xref: cpmsftngxa10.phx.gbl
microsoft.public.dotnet.framework.webservices:7761
X-Tomcat-NG: microsoft.public.dotnet.framework.webservices
"Codex Twin" <co***@more.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hello

apologies if this is the wrong newsgroup to be sending this to.

Basically, I have an ASP.NET application that I am trying to force to use

a
proxy server settings. This can be done by accessing machine.config, but
I
do not have access to the client machine.config machine.

Therefore every request made from this application must have these proxy
server settings. But I am having problems writing the code for this.

I have decdided to implement this in a HttpModule.

The code I have is in a custom BeginRequest event within the module. I

have
not been able to test it yet, but would this be the correct way to do it:
//************************************************** *********************
WebProxy wp = new WebProxy("http://my.proxy.blah", true);

HttpRequest req = ((HttpApplication)sender).Request;
HttpWebRequest hwr = (HttpWebRequest) WebRequest.Create(req.Url);
hwr.Proxy = wp;


I think it might be better to supply the full procedure code I have in my
HttpModule:

public void OnBeginRequest(object sender, EventArgs e)
{
WebProxy wp = new WebProxy("http://my.proxy.blah", true);

HttpRequest req = ((HttpApplication)sender).Request;
HttpWebRequest hwr = (HttpWebRequest) WebRequest.Create(req.Url);
hwr.Proxy = wp;
}



Nov 23 '05 #3

P: n/a
If I understand you correctly, you want all requests to your web application
to come via a proxy server?

If so, the code you showed in the aspx page should actually be used on the
client application. Or, put a proxy entry in the machine.config file on the
client machine. Or, put it in the application config file of your
application.

--
feroze

-----------------
This posting is provided as-is. It offers no warranties and assigns no
rights.

See http://weblogs.asp.net/feroze_daud for System.Net related posts.
----------------

"Codex Twin" <co***@gmail.com> wrote in message
news:41**********************@ptn-nntp-reader02.plus.net...
Hi

Sorry, I should have made this clearer. I am dealing with an ASP.NET
webforms application and not a WebService.
I know that the WebService class has a Proxy property.

In my case, I am trying to ensure that every request to the web application is routed via a proxy server URL.
I know that the HttpWebRequest class has a Proxy property as well but I do
not know how to use it. My thinking has been to try and intercept each
request within an HttpModule, but at that point I am stuck.

Thanks
"Dan Rogers" <da***@microsoft.com> wrote in message
news:2o**************@cpmsftngxa10.phx.gbl...
Hi,

There, I think, is a far simpler approach. The proxy that you generated
from an add-web-reference operation, in your client code, supports HTTP
proxies natively. Check out the Proxy property on that generated service proxy. You can create a WebProxy instance, using your named proxy, and
set
that on your service proxy. This makes the service proxy direct its
requests thru your web proxy.

I hope this helps

Dan Rogers
Microsoft Corporation
--------------------
From: "Codex Twin" <co***@more.com>
References: <#T**************@TK2MSFTNGP10.phx.gbl>
Subject: Re: Programmatically add Proxy to web request
Date: Thu, 2 Dec 2004 19:01:18 -0000
Lines: 46
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
Message-ID: <#R**************@TK2MSFTNGP15.phx.gbl>
Newsgroups: microsoft.public.dotnet.framework.webservices
NNTP-Posting-Host: 193.115.152.15
Path:
cpmsftngxa10.phx.gbl!TK2MSFTFEED01.phx.gbl!TK2MSFT NGP08.phx.gbl!TK2MSFTNGP15 phx.gbl
Xref: cpmsftngxa10.phx.gbl
microsoft.public.dotnet.framework.webservices:7761
X-Tomcat-NG: microsoft.public.dotnet.framework.webservices
"Codex Twin" <co***@more.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hello

apologies if this is the wrong newsgroup to be sending this to.

Basically, I have an ASP.NET application that I am trying to force to use
a
proxy server settings. This can be done by accessing machine.config,
but I
do not have access to the client machine.config machine.

Therefore every request made from this application must have these proxy server settings. But I am having problems writing the code for this.

I have decdided to implement this in a HttpModule.

The code I have is in a custom BeginRequest event within the module. I

have
not been able to test it yet, but would this be the correct way to do it:

//************************************************** ********************* WebProxy wp = new WebProxy("http://my.proxy.blah", true);

HttpRequest req = ((HttpApplication)sender).Request;
HttpWebRequest hwr = (HttpWebRequest) WebRequest.Create(req.Url);
hwr.Proxy = wp;


I think it might be better to supply the full procedure code I have in

my HttpModule:

public void OnBeginRequest(object sender, EventArgs e)
{
WebProxy wp = new WebProxy("http://my.proxy.blah", true);

HttpRequest req = ((HttpApplication)sender).Request;
HttpWebRequest hwr = (HttpWebRequest) WebRequest.Create(req.Url);
hwr.Proxy = wp;
}



Nov 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.