微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

IIS反向代理不使用ASP.NET中的Response.Redirect()

我正在尝试使用教程 here,herehere设置反向代理.

站点在localhost:8080上设置,反向代理使用localhost:8080 / myProxy.

处理标准链接时,一切都很好.我可以查看代理URL并按预期查看所有内容.来自localhost:8080 / myProxy / default.aspx的链接按预期转到localhost:8080 / myProxy / about.aspx.

我遇到的问题是,在使用.NET Response.Redirect()的情况下,url会更改为网站的实际位置而不是代理.

链接来自localhost:8080 / myproxy / default.aspx – >本地主机:8080 / about.aspx.

我该如何解决这个问题?

这是我的配置:

<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,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>

解决方法

很抱歉回答我自己的问题,但我认为值得为其他人提供信息:

使用Response.Redirect时,出站规则开始起作用.使用fiddler查看请求有助于解决链接发生的问题.

Response.Redirect()试图发送到/About.aspx(在响应标头中传输).

正则表达式没有提到这一点.

我需要的唯一出站规则是setting up Response_location如下:

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

入境规则保持不变.

原文地址:https://www.jb51.cc/aspnet/249346.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐