通过代理设置cookie

3

我在开发环境中使用代理,因为我想在使用仅在本地主机上工作的“编辑和继续”功能时使用真实域名。

我已经使用自定义主机将 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,这样我就可以继续使用“编辑和继续”功能。

我的本地主机如何设置通配符域名“.site.com”的 cookie?(请记住,widgets.site.com 是指向 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>
1个回答

1
根据this,您应该能够为.domain.tld设置Set-Cookie,并且它应该适用于www.domain.tld。然而,从我的测试结果来看,在Firefox中也适用于domain.tld
P.S. 您可以通过将127.0.0.1 widgets.site.com添加到C:\Windows\System32\drivers\etc\hosts|/etc/hosts,完全跳过反向代理。然后,您的计算机会将widgets.site.com解析为127.0.0.1

谢谢,如果我使用主机:127.0.0.1 widgets.site.com,我需要配置项目设置以使用外部主机,然后我将失去编辑和继续功能(这就是为什么我发布问题的原因)。 - SexyMF

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接