3

I am trying to set up a reverse proxy, using the tutorials here, here and here.

The site is set up on localhost:8080, with the reverse proxy using localhost:8080/myProxy.

When dealing with standard links, all is fine. I can view the proxy url and see everything as expected. A link from localhost:8080/myProxy/default.aspx goes to localhost:8080/myProxy/about.aspx as expected.

The problem I have is that where .NET Response.Redirect() is used, the url changes to the websites actual location instead of the proxy.

i.e. the link goes from localhost:8080/myproxy/default.aspx -> localhost:8080/about.aspx.

How can i resolve this please?

Here is my config:

<system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <urlCompression doStaticCompression="false" doDynamicCompression="false" 
                    dynamicCompressionBeforeCache="false" />
    <rewrite>
        <rules>
            <rule name="Reverse Proxy to my site" stopProcessing="true">
                <match url="^myProxy/(.*)" />
                <action type="Rewrite" url="http://localhost:8080/{R:1}" />
            </rule>
        </rules>

        <outboundRules>
            <rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1">
                <match filterByTags="A, Area, Base, Form, Frame, Head, IFrame, Img, Input, Link, Script"
                       pattern="^http(s)?://localhost:8080/(.*)" />
                <action type="Rewrite" value="/myProxy/{R:2}" />
            </rule>
            <rule name="RewriteRelativePaths" preCondition="ResponseIsHtml1">
                <match filterByTags="A, Area, Base, Form, Frame, Head, IFrame, Img, Input, Link, Script" 
                       pattern="^/(.*)" negate="false" />
                <action type="Rewrite" value="/myProxy/{R:1}" />
            </rule>
            <preConditions>
                <preCondition name="ResponseIsHtml1">
                    <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
                </preCondition>
            </preConditions>
        </outboundRules>

    </rewrite>
</system.webServer>
5

Sorry to answer my own question, but I think this is worth putting out there for others info:

When using Response.Redirect, outbound rules come into play. Viewing the requests with Fiddler helped work out what was going on with the links.

Response.Redirect() was trying to send to /About.aspx (Transport in Response Headers).

This was not being picked up by the regex.

The only outbound rule I needed was setting up Response_location as follows:

<rule name="Response Status Update" preCondition="ResponseStatus" stopProcessing="true">
  <match serverVariable="RESPONSE_Location" pattern="^/(.*)" />
  <action type="Rewrite" value="http://myServer:8080/myProxy/{R:1}" />
</rule>

The inbound rule remained unchanged.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.