473,385 Members | 1,848 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,385 software developers and data experts.

Relay Pages: Incoming to old IIS URL -> Request to new PHP Server for content -> Out to client

Hello,

note: This is for a Faculty web site that is undergoing a migration to
an open source solution so my motives are legit.

I need to build a relay from IIS handling URL_A to a PHP server
(URL_B), get the content from the PHP server (if it exists) and then
serve it out via IIS. If the content does not exist then I need to
pass the request through to the IIS server and serve the pages from
there. All of this needs to be done while retaining the existing URL_A
on the client side as we do not want to lose/change the url.

The steps I am thinking to accomplish this wonderful hack are:

1.) Trap requests to URL from IIS in a HttpModule

2.) Send a request from the HttpModule to PHP server for page content

3.) If page content is returned from PHP server then serve it out from
IIS (first changing any URL_B links to URL_A so that end user does not
see the temporary url being used by the PHP server and the IIS server
will still trap requests)

4.) If page content is not returned from PHP then pass through request
on IIS server and let it handle it.

I have had limited success trying the following classes:

HttpWebRequest,
HttpWebResponse and
HttpContext.Current.Response.OutputStream.Write.

Unfortunately, after testing my code successfully on one part of the
new web site and I am now getting -1 returned at the end of the
following code:

HttpWebResponse myHttpWebResponse=
(HttpWebResponse)myRequest.GetResponse();
Stream streamResponse=myHttpWebResponse.GetResponseStream ()
(int)myHttpWebResponse.ContentLength

Everything else in myHttpWebResponse looks to be fine and dandy.

It looks like I may have more success with:

WebClient.DownloadFile

What implications will I have with PostBacks and what if anything do I
need to do to forward/return headers?

Does anyone have experience with doing something like this and if so
could I get some pointers/heads up?

Is there a name to what I am trying to do that will help me find some
info on the internet?

Thanx in advance

Jim

Dec 4 '06 #1
7 2752
Jim,

Let me make a few suggestions. I created a project which does url
mapping for ASP.NET using an HTTP module. It is also implemented with
as a provider, so you can change how the mappings are handled by
creating your own custom implementation. It handles much of the
trouble you come across when doing url mapping. You can get the full
source here.

http://svn.offwhite.net/svn/SmallSha...lMapper/trunk/

If you just want to look at some working code, you can see the module
here.

http://svn.offwhite.net/svn/SmallSha...apperModule.cs

The default provider is a static 1 to 1 mapping which takes a
configured path and maps it to a single endpoint, like
/mappedEndpoint/*.aspx to /masterTemplate.aspx. If you were to map
multiple endpoints to ASPX pages you could have those pages load
content from the PHP pages, perhaps caching the content whenever you
can to enhance performance. (see System.Web.Caching) Note that with
IIS you need the .aspx extention to have the .NET runtime handle the
request. Otherwise the HTTP module will not be reached. With IIS 6
you can configure different extensions to be handled by the .NET
runtime.

More here on IIS and .aspx extensions:
http://www.zorched.net/2006/01/20/as...spx-extension/

I do not know enough about your requirements to know if this is the
right approach though. Instead what you may want to do is redirect the
pages to the new locations. I run both IIS and Apache websites and
host my blog on an Apache server. I was running MovableType for my
blog but eventually moved to WordPress. I moved to WordPress because
it named the blog entries by the title of the page, I needed a way to
map requests to the old locations to the new one. I think this is what
you are looking to do.

To do it I used features within Apache to handle the redirects. My old
blog was moved to /mtblog/ while my new blog stayed at /blog/.

First I mapped MovableType urls in /blog/ to the new WordPress urls
with the RedirectMatch to do the a clean move from /blog/ to /mtblog/.

RedirectMatch atom.xml$ http://brennan.offwhite.net/blog/atom/
RedirectMatch index.xml$ http://brennan.offwhite.net/blog/feed/
RedirectMatch archives.html$
http://brennan.offwhite.net/mtblog/archives.html
RedirectMatch archives/(.*)$
http://brennan.offwhite.net/mtblog/archives/$1

It just happened that MovableType generated static pages which I was
able to move over the the mtblog directory. But for the more popular
urls I wanted them to get back to the WordPress pages which had an
updated theme. So I added a url specific mapping to redirect them over
to the WordPress pages.

Redirect /mtblog/archives/000303.html
http://brennan.offwhite.net/blog/200...th-javascript/

In your case you would be mapping .aspx pages to .php so the
RedirectMatch directive will come in handy. To do this without
redirecting visitors to the new page (hiding the .php pages) you could
instead use a Url Rewriting feature. Look into the Apache module
mod_rewrite. You can have it magically accept the old url but
internally map it to a different internal url just like I do with the
UrlMapper project I listed above.

Brennan Stehling
http://brennan.offwhite.net/blog/
ASP.NET JAD (Just Another Developer)
Electric Co. wrote:
Hello,

note: This is for a Faculty web site that is undergoing a migration to
an open source solution so my motives are legit.

I need to build a relay from IIS handling URL_A to a PHP server
(URL_B), get the content from the PHP server (if it exists) and then
serve it out via IIS. If the content does not exist then I need to
pass the request through to the IIS server and serve the pages from
there. All of this needs to be done while retaining the existing URL_A
on the client side as we do not want to lose/change the url.

The steps I am thinking to accomplish this wonderful hack are:

1.) Trap requests to URL from IIS in a HttpModule

2.) Send a request from the HttpModule to PHP server for page content

3.) If page content is returned from PHP server then serve it out from
IIS (first changing any URL_B links to URL_A so that end user does not
see the temporary url being used by the PHP server and the IIS server
will still trap requests)

4.) If page content is not returned from PHP then pass through request
on IIS server and let it handle it.

I have had limited success trying the following classes:

HttpWebRequest,
HttpWebResponse and
HttpContext.Current.Response.OutputStream.Write.

Unfortunately, after testing my code successfully on one part of the
new web site and I am now getting -1 returned at the end of the
following code:

HttpWebResponse myHttpWebResponse=
(HttpWebResponse)myRequest.GetResponse();
Stream streamResponse=myHttpWebResponse.GetResponseStream ()
(int)myHttpWebResponse.ContentLength

Everything else in myHttpWebResponse looks to be fine and dandy.

It looks like I may have more success with:

WebClient.DownloadFile

What implications will I have with PostBacks and what if anything do I
need to do to forward/return headers?

Does anyone have experience with doing something like this and if so
could I get some pointers/heads up?

Is there a name to what I am trying to do that will help me find some
info on the internet?

Thanx in advance

Jim
Dec 5 '06 #2
Thanx Brennan,

Quick question, what exactly fires the

PostMapRequestHandler.

I can find much information on this handler.

Jim

Dec 6 '06 #3
Further to my original post.

The name for what I am trying to do is "Reverse Proxy"

Lots of resources on the internet using this as a search term.

Jim

Dec 6 '06 #4
Look for the ASP.NET lifecycle. You will find a full list of the
events that fire.

For the UrlMapper I had to place those events at just the right stage
in the cycle.

Brennan Stehling
http://brennan.offwhite.net/blog/
Electric Co. wrote:
Thanx Brennan,

Quick question, what exactly fires the

PostMapRequestHandler.

I can find much information on this handler.

Jim
Dec 6 '06 #5
I created a reverse proxy system with Apache using mod_perl a long time
ago. Perhaps you could use the Apache 2 features for proxying as they
are not built-in and quite powerful.

Look over this page...

http://httpd.apache.org/docs/2.2/mod/mod_proxy.html

What I use to do with IIS6 was front the databases with an Apache 2
server set up as a reverse proxy with the gzip compression features on.
It was a great way to speed up the data transfer. With some fancy
reverse proxy and url rewriting you may be able to achieve what you
want. But combining those features together can be tough. They may
call that module chaining. I have not read up on all of the latest 2.2
features.

Brennan Stehling
http://brennan.offwhite.net/blog/

Electric Co. wrote:
Further to my original post.

The name for what I am trying to do is "Reverse Proxy"

Lots of resources on the internet using this as a search term.

Jim
Dec 6 '06 #6
typo...

now instead not built-in...
Brennan Stehling wrote:
I created a reverse proxy system with Apache using mod_perl a long time
ago. Perhaps you could use the Apache 2 features for proxying as they
are not built-in and quite powerful.

Look over this page...

http://httpd.apache.org/docs/2.2/mod/mod_proxy.html

What I use to do with IIS6 was front the databases with an Apache 2
server set up as a reverse proxy with the gzip compression features on.
It was a great way to speed up the data transfer. With some fancy
reverse proxy and url rewriting you may be able to achieve what you
want. But combining those features together can be tough. They may
call that module chaining. I have not read up on all of the latest 2.2
features.

Brennan Stehling
http://brennan.offwhite.net/blog/

Electric Co. wrote:
Further to my original post.

The name for what I am trying to do is "Reverse Proxy"

Lots of resources on the internet using this as a search term.

Jim
Dec 6 '06 #7
Thanx Brennan,

I am now looking at doing the Reverse Proxy on the Apache side.

Apache seems to be a little more friendlier then IIS. That said from
first glance it looks like you can get a bit more control with IIS - at
a price though.

Seeing as we are moving away from IIS and towards APACHE it does make
sense to go whole hog right from the start.

Thanks again.

Jim

Dec 7 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Dicky Cheng | last post by:
Hi, I am using .net remoting technology. I set up a .net remoting client and server in IIS. When the client calls the server, the server will run a long duration method (30-60seconds). I have a...
7
by: DW | last post by:
Hi, Here is my question. I want to push security prices to the desktop from the server. Whenever there is a new price in the database, the server notifies the client. How can this be done in...
2
by: trint | last post by:
I have an app that uses the standard Socket Client code. I send it a message to call a function and it receives the message, debugs through the function, but the function doesn't actually fire. ...
14
by: Matt | last post by:
I want to know if ASP.NET Web Forms Validation Controls are Server-Side or Client-Side form validation? Since I think each validator control can select either 1) JavaScript based error dialog or 2)...
3
by: | last post by:
I have been researching articles on google on how to create a simple RSS feed that sucks <title><blurb><link><date> out of a sql server 2000 database via an aspx page. I know it has to be pushed...
3
by: Gerhard | last post by:
Is it possible to embed a .pdf file inside <asp:Content></asp:Content>? I have a page that has a master page with navigation, etc., and I want the content to be what is in a .pdf file. Is this...
2
by: domtam | last post by:
Hi there. My goal is to write a windows service that can act as HTTP Request server. How can I do that? I know that I can use ASP.NET to develop a web site to achieve this purpose, i.e....
11
by: K Viltersten | last post by:
In the client.js file i declare the following variable. ... var str = "info"; ... In the corresponding ASP file called server.aspx.cs i declare two following methods.
1
by: tshad | last post by:
I have a W2K3 Server we are setting up to run a Windows Service for a client at their location. I don't want this machine to go through exchange or their local mail server, I just want the...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.