473,372 Members | 1,301 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 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 9054

"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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.