I have two webapps WebApp1 and WebApp2 in two different domains.
You cannot share cookies across domains. You can however allow all subdomains to have access. To allow all subdomains of example.com
to have access, set the domain to .example.com
.
It's not possible giving otherexample.com
access to example.com
's cookies though.
Read Cookie
in Web Api
var cookie = actionContext.Request.Headers.GetCookies("newhbsslv1");
Logger.Log("Cookie " + cookie, LoggerLevel.Info);
Logger.Log("Cookie count " + cookie.Count, LoggerLevel.Info);
if (cookie != null && cookie.Count > 0)
{
Logger.Log("Befor For " , LoggerLevel.Info);
foreach (var perCookie in cookie[0].Cookies)
{
Logger.Log("perCookie " + perCookie, LoggerLevel.Info);
if (perCookie.Name == "newhbsslv1")
{
strToken = perCookie.Value;
}
}
}
As other people say, you cannot share cookies, but you could do something like this:
Of course, it's not completely secure, and you have to create some kind of internal protocol between your apps to do that.
Lastly, it would be very annoying for the user if you do something like that in every request, but not if it's just the first.
But I think there is no other way...