I have been tasked with determining how to maintain user sessions via cookies from one subdomain to another across multiple application pools. My findings so far indicate that subdomains can share cookies across pools, but I need to be able to demo this live.
I have never worked with application pools before, and I just want to have one instance of my simple cookie baking/reading web app running on pool A at localhost:3000 and another instance running on pool B at localhost:3001. Many of the answers I've found just say "create the application pool and add your app but I have trouble finding details on how to do this specifically.
The web app I'm running is this example from HttpCookieCollection.
You could follow these below steps:
Open iis manager
Create 2 websites with the below configuration:
Set the folder path site name and ip address based on your test .ip address you can select from the dropdown and choose the folder path as your website publish folder.
Repeat same steps and create second website.
Add the entries as shown below instead of 127.0.0.1 use your machine ip
To share the cookie you could use thie below code:
protected void SetCookieButton_Click(object sender, EventArgs e)
{
// Create and set cookie
HttpCookie cookie = new HttpCookie("MySharedCookie", "Hello from AppA");
cookie.Domain = ".domain.com"; // Sharing across subdomains
cookie.Path = "/";
cookie.Expires = DateTime.Now.AddDays(1);
Response.Cookies.Add(cookie);
// Refresh page to show the cookie value
Response.Redirect(Request.Url.AbsoluteUri);
}
Or use this code in web.config file:
<system.web>
<httpCookies domain=".domain.com" />
</system.web>
Test Result: