title: Single sign-on not working correctly using different application pools?
body: <p>I have found out by creating 2 new websites under IIS 7 that single sign-on authentication doesn't work when run in different application pools. When i move the applications into the same pool i can login on one of them and be logged in on the other one. When i change application pool on one of them, i don't get logged in on the second one.</p>
  
  <p>Is there any settings that can be set in the machine.config file to allow them to share the same cookie over application pools?</p>
  
  <hr>
  
  <p>Ex. 1:
  proj1 (app pool .net 2)</p>
  
  <p>proj2 (app pool .net 2)</p>
  
  <p>= Single sign-on works, they are sharing the same auth cookie.</p>
  
  <hr>
  
  <p>Ex. 2:
  proj1 (app pool .net 2)</p>
  
  <p>proj2 (app pool .net 4, integrated/classic)</p>
  
  <p>= Single sign-on does not work, they are NOT sharing the same auth cookie.</p>
  
  <hr>
  
  <p>Ex. 2:
  proj1 (app pool .net 4, integrated/classic)</p>
  
  <p>proj2 (app pool .net 4, integrated/classic)</p>
  
  <p>= Single sign-on works, they are sharing the same auth cookie.</p>
  
  <hr>
  
  <p><strong>Original post</strong></p>
  
  <p><strong>Latest update at the bottom</strong></p>
  
  <p>I have 2 projects, one is an asp.net webforms and the other is a mvc 3 project.</p>
  
  <p>I followed this guide, see at the bottom, and i got it working on my computer. But when i upload it to the server, it doesn't work anymore. The differences that i can think of is, 1) on the server we are using SSL, 2) the webforms project is using .net 2 and the MVC project is using .net 4 (integrated mode) and 3) I use IIS 7 on the server and i use VS 2008/2010 to test it on my local machine. </p>
  
  <p>asp.net MVC 3 (.net 4)</p>
  
  <pre><code>&lt;forms name=".ASPXAUTH" loginUrl="~/Home/Login" timeout="30" enableCrossAppRedirects="true" domain=".mydomain.com" ticketCompatibilityMode="Framework20" /&gt;
  </code></pre>
  
  <p>Webforms (.net 2)</p>
  
  <pre><code>&lt;forms name=".ASPXAUTH" loginUrl="Default.aspx" defaultUrl="Default.aspx" timeout="30" domain=".mydomain.com" enableCrossAppRedirects="true" /&gt;
  </code></pre>
  
  <p>The funny part is, i uploaded a test.aspx page to both the Mvc (.net 4) and the webforms (.net) project and that just displays some trace.</p>
  
  <p>Both projects have the same sessionid and .ASPXAUTH. On my localhost i can access the ASPXAUTH on the mvc project but i can't access it on the server.</p>
  
  <p>The projects run as subdomains, mvc.mydomain.com and webforms.mydomain.com.</p>
  
  <p>Anyone got any ideas on how to solve this? I have full access to the IIS 7.0.</p>
  
  <p>(I have also tried turning SSL on the server off but i still get the same result)</p>
  
  <p>Guide for authentication sharing:
  <a href="http://www.codeproject.com/KB/aspnet/SingleSignon.aspx" rel="nofollow">http://www.codeproject.com/KB/aspnet/SingleSignon.aspx</a></p>
  
  <p><strong>Updated</strong>
  I also tried this: (webforms .net 2.0)</p>
  
  <pre><code>var ticket = new FormsAuthenticationTicket(1, "authtest", DateTime.Now, DateTime.Now.AddMinutes(30), false, login.Email);
  var enc = FormsAuthentication.Encrypt(ticket);
  var cookie = new HttpCookie("authcookie", enc) {Domain = ".mydomain.com"};
  Response.Cookies.Add(cookie);
  </code></pre>
  
  <p>and in mvc 3 (.net 4)</p>
  
  <pre><code>FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(HttpContext.Request.Cookies["authcookie"].Value);
  ViewBag.User = "User: " + ticket.Name;
  </code></pre>
  
  <p>This throws the following error: "Length of the data to decrypt is invalid."</p>
  
  <p><strong>Updated 6th jul</strong></p>
  
  <p>Funny! When i add 2 new domains that runs under .net 2 it works perfectly. But when i change the application pool to .net 4 it stops working. Its like they aren't compatible or i might be missing a setting somewhere</p>