I would like to setup a reverse proxy in IIS but in my configuration I get problems with ASP.NET postbacks. When you click on any submit button of the proxied website then you get a 404 error. The URL in browser address bar is changed to the rewritten URL.
For example, the website that I need to proxy is http://website.com/host. Here http://website.com and http://website.com/host are separate web applications. Host is running as a virtual folder under website.com.
I want to access the Host from this URL: http://me.local/myhost. In IIS me.local is an asp.net web application and Myhost is added as another application as child of me.local. Everything works just fine as long as you don't click on submit button anywhere on
the proxied website. Once you do this then you get to page http://me.local/host which results in 404 error. When you look at page's html source then form's action url is set correctly to /myhost
Why does the error happen? Is it possible to fix it in IIS, or do we need to make changes to the host application?
My server is running IIS 8.5. The host server is an old one with IIS 6, and web application can be asp.net 1.1 or asp.net 2.0.
The section with rewrite rules from web.config of "myhost" application is:
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Route the requests for host" stopProcessing="true">
<match url="^(.*)" />
<conditions>
<add input="{CACHE_URL}" pattern="^(https?)://" />
</conditions>
<action type="Rewrite" url="{C:1}://website.com/host/{R:1}" />
<serverVariables>
<set name="HTTP_ACCEPT_ENCODING" value="" />
</serverVariables>
</rule>
<rule name="hostToDefault" stopProcessing="true">
<match url="^" />
<conditions>
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
</conditions>
<action type="Redirect" url="default.aspx" appendQueryString="false" />
</rule>
<rule name="RedirectUserFriendlyURL1" stopProcessing="true">
<match url="^(.*)default\.aspx$" />
<conditions>
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
</conditions>
<action type="Redirect" url="(.*)" appendQueryString="false" />
</rule>
</rules>
<outboundRules>
<rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1">
<match filterByTags="A, Area, Base, Form, Frame, Head, IFrame, Img, Input, Link, Script" pattern="^http(s)?://website.com/(.*)" />
<action type="Rewrite" value="/{R:2}" />
</rule>
<rule name="NonhostRewriteRelativePaths" preCondition="ResponseIsHtml1">
<match filterByTags="A, Area, Base, Form, Frame, Head, IFrame, Img, Input, Link, Script" pattern="^/(?!host)(.*)" negate="false" />
<action type="Rewrite" value="http://website.com/{R:1}" />
</rule>
<rule name="hostRelativePaths" preCondition="ResponseIsHtml1">
<match filterByTags="A, Area, Base, Form, Frame, Head, IFrame, Img, Input, Link, Script" pattern="^/host/(.*)" negate="false" />
<action type="Rewrite" value="/myhost/{R:1}" />
</rule>
<rule name="OutboundRewriteUserFriendlyURL1" preCondition="ResponseIsHtml1">
<match filterByTags="A, Form, Img" pattern="^(.*)myhost/default\.aspx$" />
<action type="Rewrite" value="{R:1}/myhost/default" />
</rule>
<preConditions>
<preCondition name="ResponseIsHtml1">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>
<urlCompression doStaticCompression="false" doDynamicCompression="false" />
</system.webServer>
</configuration>