ReverseProxy for IIS 6.0 in CS using ASP.NET: Difference between revisions
No edit summary |
m (→Uninstalling) |
||
(18 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
== Problem to solve == |
== Problem to solve == |
||
We want to embed content from |
We want to embed content from an internal webserver e.g. <code><nowiki>http://foo</nowiki></code> to our public webserver |
||
<code><nowiki>http://sar.informatik.hu-berlin.de</nowiki></code>. In particular the frontend request |
<code><nowiki>http://sar.informatik.hu-berlin.de</nowiki></code>. In particular the frontend request |
||
<code><nowiki>http://sar.informatik.hu-berlin.de/test/bla.html</nowiki></code> should get the response for <code><nowiki>http://foo/dir/bla.html</nowiki></code>. |
<code><nowiki>http://sar.informatik.hu-berlin.de/test/bla.html</nowiki></code> should get the response for <code><nowiki>http://foo/dir/bla.html</nowiki></code>. |
||
Thus the mapping is: |
Thus the mapping is: |
||
* <code><nowiki> |
* <code><nowiki>http://sar.informatik.hu-berlin.de/test -> http://foo/dir</nowiki></code>. |
||
From outside this |
From outside this should be look like a local web directory. |
||
== Used Software == |
== Used Software == |
||
[http://www.saltypickle.com/Home/16 IIS Reverse Proxy] in particular [http://www.saltypickle.com/Home/uploads/16/ReverseProxy(v1.5).zip v1.5]. |
|||
In that release of software redirections of the backend server are not forwarded transparently to the frontend. Therfore we patched the C-Sharpe code to take care of that. We disabled the internal handling <code>MaximumRedirections = 0;</code> of redirections and send them instead through the frontend to the browser. |
|||
The differences are: |
|||
<pre>constki>38MaximumRedirections< constt intMaximumRedirectionss = 50; |
|||
<pre><nowiki> |
|||
38c38 |
|||
< const int MaximumRedirections = 50; |
|||
--- |
--- |
||
> const int |
> const int MaximumRedirections = 0; |
||
357a358,370 |
|||
> switch((int) backEndResponse.StatusCode) { |
> switch((int) backEndResponse.StatusCode) { |
||
> case 301: |
> case 301: |
||
> case 302: |
> case 302: |
||
> case 303: |
|||
> cfrontEndResponseoStatusCodeesponse> case 307newLocationsponse> newLocationponRegexatusCode newLocationkEbackEndSiteStatusCode; |
|||
> case 307: |
|||
⚫ | |||
> frontEndResponse. |
> frontEndResponse.StatusCode = (int) backEndResponse.StatusCode; |
||
⚫ | |||
> newLocation = Regex.Replace(newLocation, backEndSite, |
|||
> frontEndRequest.Url.GetLeftPart(UriPartial.Authority) + frontEndRequest.ApplicationPath, |
|||
> RegexOptions.IgnoreCase); |
> RegexOptions.IgnoreCase); |
||
> |
> frontEndResponse.RedirectLocation = newLocation; |
||
> |
> break; |
||
> |
> }</nowiki> |
||
</pre> |
|||
⚫ | |||
Complete [[ReverseProxy.cs]]. |
|||
⚫ | |||
== Installation == |
== Installation == |
||
Based on [http://www.saltypickle.com/Home/20 W2k/XP], [http://www.saltypickle.com/Home/19 Win2003] |
Based on [http://www.saltypickle.com/Home/20 W2k/XP], [http://www.saltypickle.com/Home/19 Win2003] |
||
=== Walk through === |
|||
# |
# Create directory where software lives e.g. <code>C:\Inetpub\test_virtual</code> and extract archive <code>"\\dc\pub\2006\2006 Software\ReverseProxy_15_SAR.zip"</code> to that directory. [[Image:rproxy_1.png]] |
||
# Create in |
# Create in the IIS MMC a virtual directory [[Image:rproxy_2.png]] |
||
# |
# Give the alias name under which the resource should be reachable by the frontend <code>test</code> [[Image:rproxy_3.png]] |
||
# Select the Web Site |
# Select the Web Site Content Directory <code>C:\Inetpub\test_virtual</code> [[Image:rproxy_4.png]] |
||
# OK. [[Image:rproxy_5.png]] |
# OK. [[Image:rproxy_5.png]] |
||
# |
# Check the Properties of the virtual dir. [[Image:rproxy_6.png]] |
||
# |
# Press Create. [[Image:rproxy_7.png]] |
||
# Press Configuration [[Image:rproxy_8.png]] |
# Press Configuration [[Image:rproxy_8.png]] |
||
# Insert [[Image:rproxy_9.png]] |
# Insert [[Image:rproxy_9.png]] |
||
# Enter: Executable <code>C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll</code> and uncheck "Verify that file exists" [[Image:rproxy_10.png]] |
# Enter: Executable <code>C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll</code> and uncheck "Verify that file exists" [[Image:rproxy_10.png]] |
||
# If you |
# If you select <code>.asax</code> and then press Edit it should look like that: [[Image:rproxy_11.png]] |
||
# Open cmd |
# Open cmd-prompt and to register <code>ICSharpCode.SharpZipLib.dll</code> and run <pre><nowiki>cd C:\Inetpub\test_virtual |
||
C:\Inetpub\test_virtual>C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\gacutil.exe /i ICSharpCode.SharpZipLib.dll</nowiki></pre> [[Image:rproxy_12.png]] |
C:\Inetpub\test_virtual>C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\gacutil.exe /i ICSharpCode.SharpZipLib.dll</nowiki></pre> [[Image:rproxy_12.png]] |
||
# |
# Finally you have to configure the proxy by editing <code>C:\Inetpub\test_virtual\Web.config</code><pre><nowiki><?xml version="1.0" encoding="utf-8" ?> |
||
<configuration> |
<configuration> |
||
Line 53: | Line 63: | ||
== Uninstalling == |
== Uninstalling == |
||
* Unregister the gzip- |
* Unregister the gzip-dll by running <code>gacutil /u ICSharpCode.SharpZipLib.dll</code>. |
||
* Remove the virtual directory <code>test</code> in the IIS-MMC. |
* Remove the virtual directory <code>test</code> in the IIS-MMC. |
||
* Remove the directory <code>C:\Inetpub\test_virtual</code>. |
* Remove the directory <code>C:\Inetpub\test_virtual</code>. |
||
--[[User:Wolfm|WM]] 12:54, 13 December 2006 (CET) |
Latest revision as of 11:54, 13 December 2006
Problem to solve
We want to embed content from an internal webserver e.g. http://foo
to our public webserver
http://sar.informatik.hu-berlin.de
. In particular the frontend request
http://sar.informatik.hu-berlin.de/test/bla.html
should get the response for http://foo/dir/bla.html
.
Thus the mapping is:
http://sar.informatik.hu-berlin.de/test -> http://foo/dir
.
From outside this should be look like a local web directory.
Used Software
IIS Reverse Proxy in particular v1.5.
In that release of software redirections of the backend server are not forwarded transparently to the frontend. Therfore we patched the C-Sharpe code to take care of that. We disabled the internal handling MaximumRedirections = 0;
of redirections and send them instead through the frontend to the browser.
The differences are:
38c38 < const int MaximumRedirections = 50; --- > const int MaximumRedirections = 0; 357a358,370 > switch((int) backEndResponse.StatusCode) { > case 301: > case 302: > case 303: > case 307: > frontEndResponse.StatusCode = (int) backEndResponse.StatusCode; > string newLocation = backEndResponse.Headers["Location"]; > newLocation = Regex.Replace(newLocation, backEndSite, > frontEndRequest.Url.GetLeftPart(UriPartial.Authority) + frontEndRequest.ApplicationPath, > RegexOptions.IgnoreCase); > frontEndResponse.RedirectLocation = newLocation; > break; > }
Complete ReverseProxy.cs.
Then redirections which usally occur if you enter e.g. http://foo/dir -> http://foo/dir/
are forwarded to the browser as http://sar.informatik.hu-berlin.de/test -> http://sar.informatik.hu-berlin.de/test/
Installation
Walk through
- Create directory where software lives e.g.
C:\Inetpub\test_virtual
and extract archive"\\dc\pub\2006\2006 Software\ReverseProxy_15_SAR.zip"
to that directory. - Create in the IIS MMC a virtual directory
- Give the alias name under which the resource should be reachable by the frontend
test
- Select the Web Site Content Directory
C:\Inetpub\test_virtual
- OK.
- Check the Properties of the virtual dir.
- Press Create.
- Press Configuration
- Insert
- Enter: Executable
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll
and uncheck "Verify that file exists" - If you select
.asax
and then press Edit it should look like that: - Open cmd-prompt and to register
ICSharpCode.SharpZipLib.dll
and runcd C:\Inetpub\test_virtual
C:\Inetpub\test_virtual>C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\gacutil.exe /i ICSharpCode.SharpZipLib.dll
- Finally you have to configure the proxy by editing
C:\Inetpub\test_virtual\Web.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings> <add key="BackEndSite" value="http://foo/dir" /> </appSettings>
<system.web>
...
Uninstalling
- Unregister the gzip-dll by running
gacutil /u ICSharpCode.SharpZipLib.dll
. - Remove the virtual directory
test
in the IIS-MMC. - Remove the directory
C:\Inetpub\test_virtual
.
--WM 12:54, 13 December 2006 (CET)