Re: Programmatically add Proxy to web request

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Dan Rogers (danro_at_microsoft.com)
Date: 12/03/04


Date: Fri, 03 Dec 2004 23:26:33 GMT

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" <codex@gmail.com>
Newsgroups: microsoft.public.dotnet.framework.webservices
References: <#T58K$J2EHA.1296@TK2MSFTNGP10.phx.gbl>
<#RWbQFK2EHA.2804@TK2MSFTNGP15.phx.gbl>
<2oMCGLL2EHA.1512@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: <41af8d9d$0$9328$ed2619ec@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: abuse@plus.net
Path:
cpmsftngxa10.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.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" <danro@microsoft.com> wrote in message
news:2oMCGLL2EHA.1512@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" <codex@more.com>
> References: <#T58K$J2EHA.1296@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: <#RWbQFK2EHA.2804@TK2MSFTNGP15.phx.gbl>
> Newsgroups: microsoft.public.dotnet.framework.webservices
> NNTP-Posting-Host: 193.115.152.15
> Path:
>
cpmsftngxa10.phx.gbl!TK2MSFTFEED01.phx.gbl!TK2MSFTNGP08.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" <codex@more.com> wrote in message
> news:%23T58K$J2EHA.1296@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;
> }
>
>
>
>
>



Relevant Pages

  • Re: ISA Server Problems, please help
    ... Based on the rules you have listed, SecureNAT clients should only be allowed ... The All access rule for SBS Internet Users ... Web Proxy and/or Firewall Client ... > header to the publishing server instead of the actual one. ...
    (microsoft.public.windows.server.sbs)
  • Re: Making a socket connection via a proxy server
    ... > It looks like the Tiny HTTP Proxy (using BaseHTTPServer as it's ... between client and server. ... When sending a HTTP GET request to a server, ...
    (comp.lang.python)
  • Re: writing a proxy ..
    ... the browser but I get a BAD REQUEST. ... I dont quite understand your code, To clear things up, is this code for an http proxy? ... if so why does the request originate with the proxy and where does your browser come into it. ... Can you explain the architecture of this thing, I usually expect there to be a Client talking to a Proxy which relays the request to a Server. ...
    (comp.lang.java.programmer)
  • RE: Simple ISA 2004 questions
    ... You'd better create a new GPO for IE proxy, ... Run "gpmc.msc" in SBS server, ... ISA Server 2004 Query can give you some help. ... In the Microsoft Internet Security and Acceleration Server 2004 console, ...
    (microsoft.public.windows.server.sbs)
  • Re: how to explain these logs?
    ... :Someone who oriented privacy at 210.21.30.169 searched proxy server. ... I just tried the following request on an RH7.1 with Apache 1.3.19 ... I have disabled the proxy in Apache. ...
    (comp.os.linux.security)