Reputation: 173
I want send a redirect(String) response from my controller to redirect customer to a partner web page.
Before redirecting, I want to add some cookies. I tried like following:
response().setCookie(cookie.getName(), cookie.getValue());
return redirect(redirectUrl);
However, when redirection happens, cookies are not set and hence not sent to partner web page.
How can I add cookies before redirection?
Regards, Suraj
Upvotes: 2
Views: 1108
Reputation: 11096
A cookie can not be shared between two domains (except sub-domains). You need two cookies on both domains with similar name and value. This is possible by redirecting visitors to partner website while you send cookie name and cookie value as query to a special page of partner website. They set the cookie on their domains and redirect back the visitor to your website again.
For security reasons it is recommended to encrypt query data to prevent visitors to simulate other cookies by fake names and values.
Upvotes: 1