Change domain of Kentico CurrentContact cookie

2019-08-19 09:29发布

问题:

I have a Kentico installation at sub.mydomain.com. The CurrentContact cookie is created using a domain of sub.mydomain.com. I want the cookie to be able to be read by other subdmains like app.mydomain.com.

Is there a way to accomplish this? Is there a web.config setting or a system event in which we can change the cookie domain?

回答1:

If a cookie is issued for .mydomain.com then it will be accessible on all sub domains i.e. sub. and app. but not vice versa. Technically is sub.mydomain.com and app.mydomain.com are two different domains from a browser prospective. I think you need to enable CORS support for domain app.domain.com in your Kentico web.config. You may try to add something like this to your web.config:

<httpProtocol>
  <customHeaders>
    <remove name="X-Powered-By" />
    <add name="Access-Control-Allow-Headers" value="Origin, X-Requested-With, Content-Type, Accept" />
    <add name="Access-Control-Allow-Methods" value="POST,GET,OPTIONS,PUT,DELETE" />
<add name="Access-Control-Allow-Origin" value="http://app.mydomain.com" />
<add name="Access-Control-Allow-Credentials" value="true" />
  </customHeaders>
</httpProtocol>