我想在IIS中设置反向代理,但在我的配置中,我遇到了ASP.NET回发问题。当您单击代理网站的任何提交按钮时,您会收到404错误。浏览器地址栏中的URL更改为重写的URL。
例如,我需要代理的网站是http://website.com/host。此处http://website.com和http://website.com/host是单独的Web应用程序。主机在website.com下作为虚拟文件夹运行。
我想通过以下网址访问主持人:http://me.local/myhost。在IIS中,me.local是一个asp.net Web应用程序,Myhost作为另一个应用程序添加为me.local的子项。只要您不在代理网站上的任何地方点击提交按钮,一切都会正常工作。执行此操作后,您将转到页面http://me.local/host,这会导致404错误。当你查看页面的html源代码时,表单的动作url被正确设置为/ myhost
为什么会发生错误?是否可以在IIS中修复它,或者我们是否需要对主机应用程序进行更改?
我的服务器正在运行IIS 8.5。主机服务器是旧的IIS 6,Web应用程序可以是asp.net 1.1或asp.net 2.0。
“myhost”应用程序的web.config中包含重写规则的部分是:
<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>