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