通过代理设置cookie

时间:2016-06-22 20:11:53

标签: iis 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,其自定义主机作为localhost:9090的反向代理,因此我可以继续使用编辑并继续功能。

我的localhost如何将cookie设置为通配符域“ .site.com ”? (请记住,widgets.site.comlocalhost: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>

1 个答案:

答案 0 :(得分:1)

根据this,您应Set-Cookie .domain.tld www.domain.tlddomain.tld适用127.0.0.1 widgets.site.com。但是从我的测试来看,它似乎也适用于C:\Windows\System32\drivers\etc\hosts(在firefox中)。

P.S。您可以将/etc/hosts添加到widgets.site.com | 127.0.0.1,完全跳过反向代理。然后,您的计算机会将<div class="checkbox" style="margin: 0px 6px; height: 12px;display:inline;"><input id="view:_id1:_id2:callback1:viewPanel1:0:viewColumn12:_colcbox" type="checkbox" name="view:_id1:_id2:callback1:viewPanel1:0:viewColumn12:_colcbox" value="5898E"></div> 解析为 $('body').bind('click',function(){ //your code here });

相关问题