简体   繁体   English

通过代理设置cookie

[英]Setting up a cookie via proxy

I am using a proxy in the dev environment because I want to use real domain while using the "Edit and Continue" feature that works only on localhost. 我在开发环境中使用代理,因为我想在使用仅适用于localhost的“编辑并继续”功能时使用真实域。

I have configured www.site.com on my local machine with custom host. 我已在本地计算机上使用自定义主机配置www.site.com (simple html page) (简单的html页面)

I have this app: localhost:9090 which is my asp.net mvc app on my local pc. 我有这个应用程序: localhost:9090这是我在我的本地电脑上的asp.net mvc应用程序。 www.site.com call via ajax cors to localhost:9090 , but localhost cant create cookies with the domain " .site.com ". www.site.com通过ajax cors致电localhost:9090 ,但localhost无法使用域名“ .site.com ”创建cookie。

So, I have created: widgets.site.com with custom host as a REVERSE PROXY to localhost:9090 so I can keep using Edit And Continue Feature. 所以,我创建了: widgets.site.com ,将自定义主机作为REVERSE PROXY到localhost:9090这样我就可以继续使用编辑并继续功能了。

How can my localhost set a cookie to the wildcard domain " .site.com " ? 我的localhost如何将cookie设置为通配符域“ .site.com ”? (Remember, widgets.site.com is a proxy to localhost:9090 ) (请记住, widgets.site.comlocalhost:9090的代理localhost:9090

Here is the reverse proxy: 这是反向代理:

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

According to this you should be able to Set-Cookie for .domain.tld and it should work for www.domain.tld . 根据这个,你应该能够为.domain.tld Set-Cookie ,它应该适用于www.domain.tld However from my tests it seems that it works on domain.tld as well (in firefox). 但是从我的测试看来它似乎也适用于domain.tld (在firefox中)。

PS You can skip reverse proxy altogether by adding 127.0.0.1 widgets.site.com to C:\\Windows\\System32\\drivers\\etc\\hosts | PS您可以通过将127.0.0.1 widgets.site.com添加到C:\\Windows\\System32\\drivers\\etc\\hosts来完全跳过反向代理。 /etc/hosts . /etc/hosts Then your machine would resolve widgets.site.com to 127.0.0.1 . 然后您的计算机将widgets.site.com解析为127.0.0.1

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

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