472,356 Members | 1,751 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,356 software developers and data experts.

Programmatically add Proxy to web request

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
3 8885

"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Fuzzyman | last post by:
In a nutshell - the question I'm asking is, how do I make a socket conenction go via a proxy server ? All our internet traffic has to go through a proxy-server at location 'dav-serv:8080' and I...
8
by: Tim Reynolds | last post by:
Our .Net application calls a web method of aplpication 2 that resides on their Apache server. When I as a developer C#, Studios 2003, make the call to their web method from my desktop, I receive no...
13
by: trpost | last post by:
I am looking to make a small web app that will return the status of a website from the client browser. I tried this with AJAX and it worked great locally, but did not work for remote users...
3
by: itay_k | last post by:
Hi, I am running the following simple code (just open connection to some https page with proxy): proxy= '666.179.227.666:80' proxy=urllib2.ProxyHandler({"https":'https://'+proxy}) opener =...
3
by: The Man From SQL | last post by:
Hi there, Here's the problem: our team is working on a web service which formerly took in two user defined types consisting of mostly simple datatypes. Recently we decided to move toward an XML...
0
by: paulshannon | last post by:
Hi All, We've been using Request.IsSecureConnection for some time to drop in and out of SSL for various sections of our web application. We have recently change server architecture though as we...
7
by: chandru1782 | last post by:
Dear friends, I am trying to use CPAN for installing some perl modules. i am using a ubuntu system, which has internet connection through lan and authenticated proxy. when trying to install...
1
by: =?iso-8859-1?Q?David_S=E1nchez_Mart=EDn?= | last post by:
Hi! I've seen the message below in this python list, that seems to be unanswered. I'm trying to do the pretty same thing. There's a way to preprocess the request with a mod_python handler...
1
by: dtown22 | last post by:
I am trying to make a copy of all the files involved in a web request from a specific website (i.e. you enter groups.google.com, and hit enter once and then basically make a copy of all the files...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
1
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. header("Location:".$urlback); Is this the right layout the...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
0
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.