ReverseProxy for IIS 6.0 in CS using ASP.NET: Difference between revisions

From
Jump to navigation Jump to search
Line 48: Line 48:
# 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 saelect <code>.asax</code> and then press Edit it should look like that: [[Image:rproxy_11.png]]
# If you select <code>.asax</code> and then press Edit it should look like that: [[Image:rproxy_11.png]]
# Open cmd-promt and to register <code>ICSharpCode.SharpZipLib.dll</code> and run <pre><nowiki>cd C:\Inetpub\test_virtual
# 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]]
# Finallly 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" ?>
# 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>



Revision as of 08:31, 15 May 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

Based on W2k/XP, Win2003

Walk through

  1. 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. Rproxy 1.png
  2. Create in the IIS MMC a virtual directory Rproxy 2.png
  3. Give the alias name under which the resource should be reachable by the frontend test Rproxy 3.png
  4. Select the Web Site Content Directory C:\Inetpub\test_virtual Rproxy 4.png
  5. OK. Rproxy 5.png
  6. Check the Properties of the virtual dir. Rproxy 6.png
  7. Press Create. Rproxy 7.png
  8. Press Configuration Rproxy 8.png
  9. Insert Rproxy 9.png
  10. Enter: Executable C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll and uncheck "Verify that file exists" Rproxy 10.png
  11. If you select .asax and then press Edit it should look like that: Rproxy 11.png
  12. Open cmd-prompt and to register ICSharpCode.SharpZipLib.dll and run
    cd C:\Inetpub\test_virtual

C:\Inetpub\test_virtual>C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\gacutil.exe /i ICSharpCode.SharpZipLib.dll Rproxy 12.png

  1. 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.