繁体   English   中英

通过代理设置cookie

[英]Setting up a cookie via proxy

我在开发环境中使用代理,因为我想在使用仅适用于localhost的“编辑并继续”功能时使用真实域。

我已在本地计算机上使用自定义主机配置www.site.com (简单的html页面)

我有这个应用程序: localhost:9090这是我在我的本地电脑上的asp.net mvc应用程序。 www.site.com通过ajax cors致电localhost:9090 ,但localhost无法使用域名“ .site.com ”创建cookie。

所以,我创建了: widgets.site.com ,将自定义主机作为REVERSE PROXY到localhost:9090这样我就可以继续使用编辑并继续功能了。

我的localhost如何将cookie设置为通配符域“ .site.com ”? (请记住, widgets.site.comlocalhost:9090的代理localhost:9090

这是反向代理:

<rewrite>   
    <rules>
        <rule name="ReverseProxyInboundRule1" stopProcessing="true">
            <match url="(.*)" />
            <action type="Rewrite" url="http://localhost:9090/{R:1}" />
          <conditions>
            <add input="{HTTP_COOKIE}" pattern="(.*)" />
          </conditions>
          <serverVariables>
            <set name="HTTP_ACCEPT_ENCODING" value="" />
            <set name="HTTP_COOKIE" value="{c:1}" />
          </serverVariables>
        </rule>
    </rules>
    <outboundRules>
        <rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1">
            <match filterByTags="A, Form, Img" pattern="^http(s)?://widgets.site.com/(.*)" />
            <action type="Rewrite" value="http{R:1}://localhost/{R:2}" />
        </rule>
        <preConditions>
            <preCondition name="ResponseIsHtml1">
                <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
            </preCondition>
        </preConditions>
    </outboundRules>
</rewrite>

根据这个,你应该能够为.domain.tld Set-Cookie ,它应该适用于www.domain.tld 但是从我的测试看来它似乎也适用于domain.tld (在firefox中)。

PS您可以通过将127.0.0.1 widgets.site.com添加到C:\\Windows\\System32\\drivers\\etc\\hosts来完全跳过反向代理。 /etc/hosts 然后您的计算机将widgets.site.com解析为127.0.0.1

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM