加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

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

发布时间:2020-12-15 22:35:45 所属栏目:asp.Net 来源:网络整理
导读:我正在尝试使用教程 here,here和 here设置反向代理. 该站点在localhost:8080上设置,反向代理使用localhost:8080 / myProxy. 处理标准链接时,一切都很好.我可以查看代理URL并按预期查看所有内容.来自localhost:8080 / myProxy / default.aspx的链接按预期
我正在尝试使用教程 here,here和 here设置反向代理.

该站点在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>

入境规则保持不变.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读