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.
I have configured www.site.com
on my local machine with custom host. (simple html page)
I have this app: localhost:9090
which is my asp.net mvc app on my local pc. www.site.com
call via ajax cors to localhost:9090
, but localhost cant create cookies with the domain " .site.com ".
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.
How can my localhost set a cookie to the wildcard domain " .site.com " ? (Remember, widgets.site.com
is a proxy to 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
. However from my tests it seems that it works on domain.tld
as well (in firefox).
PS You can skip reverse proxy altogether by adding 127.0.0.1 widgets.site.com
to C:\\Windows\\System32\\drivers\\etc\\hosts
| /etc/hosts
. Then your machine would resolve widgets.site.com
to 127.0.0.1
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.