4

I have a local website on ASP.NET. And I need to proxy some of the static content (from folder "static") to another website.

I've added this rule:

<rule name="All in static folder" stopProcessing="true">
    <match url="^static/.*" />
    <action type="Rewrite" url="http://otherwebsite.com/{R:0}" appendQueryString="true" logRewrittenUrl="true" />
</rule>

But that doesn't work - based on failed request log my route matches (PATTERN_MATCH step has Matched "true", then I see correct url in REWRITE_ACTION and RULE_EVALUATION_END) but I see that ASP.NET continue to evaluate other modules after this and so trying to serve the content by itself, hitting the static file handler and getting 404 (because there are not such files on the disk).

I do have access to the rewritten file (files like http://otherwebSite.com/static/stylesheet.css opened in browser without any problem). Also writing some other alias (in etc/hosts) and opening http://otherwebSiteLocalAlias.com/static/stylesheet.css also works (meaning that website does not have some host/proxy verification mechanism).

Changing action to "redirect" also works but it's not acceptable in my case.

I have another rule that proxifying a non static resource (folder url like /mypage/) to the same host and it works. It's just does not work with static files - it seems like after url rewrite done it's job properly the request continue to be handled by asp.net which shouldn't be the case.

Michael Logutov
  • 2,551
  • 4
  • 28
  • 32

1 Answers1

0

Install ARR 3.0 and "Enable proxy" for Application Request Routing to allow <action type="Rewrite" .. /> to rewrite to a different domain.

enter image description here

Here's how to install ARR 3.0 and Enable proxy with chocolatey and powershell.

# download chocolatey
iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))
choco feature enable -n allowGlobalConfirmation

# install web platform installer cli
choco install webpicommandline -y

#install ARR 3.0
WebpiCmd /Install /Products:"ARRv3_0" /AcceptEULA

# enable proxy on root IIS web server
Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST'  -filter "system.webServer/proxy" -name "enabled" -value "True"
kavun
  • 3,358
  • 3
  • 25
  • 45
  • Ofcourse I have this installed, otherwise it would be pointless to add "rule" section to web.config. The point is that it's not stopping request pipeline after it has been rewritten by proxy module. – Michael Logutov May 14 '15 at 07:19
  • What I experienced without ARR Proxy is that a "Rewrite" rule to the same domain, ie: `` works fine, but ARR Proxy had to be enabled to enable rewriting to a separate domain, ie: including `http://domain` in the action URL. My next step would be to set up two simple IIS sites (siteA, and siteB) with only a index.html in them and creating a rule like `` to see if that works. – kavun May 14 '15 at 12:21
  • I have this installed and enabled. And it worked (catching up the rule and performing rewrite) it's just it continue to process request down to pipeline and eventually ending with static file handler. – Michael Logutov May 15 '15 at 07:32