4

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.

Is there any settings that can be set in the machine.config file to allow them to share the same cookie over application pools?


Ex. 1: proj1 (app pool .net 2)

proj2 (app pool .net 2)

= Single sign-on works, they are sharing the same auth cookie.


Ex. 2: proj1 (app pool .net 2)

proj2 (app pool .net 4, integrated/classic)

= Single sign-on does not work, they are NOT sharing the same auth cookie.


Ex. 2: proj1 (app pool .net 4, integrated/classic)

proj2 (app pool .net 4, integrated/classic)

= Single sign-on works, they are sharing the same auth cookie.


Original post

Latest update at the bottom

I have 2 projects, one is an asp.net webforms and the other is a mvc 3 project.

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.

asp.net MVC 3 (.net 4)

<forms name=".ASPXAUTH" loginUrl="~/Home/Login" timeout="30" enableCrossAppRedirects="true" domain=".mydomain.com" ticketCompatibilityMode="Framework20" />

Webforms (.net 2)

<forms name=".ASPXAUTH" loginUrl="Default.aspx" defaultUrl="Default.aspx" timeout="30" domain=".mydomain.com" enableCrossAppRedirects="true" />

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.

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.

The projects run as subdomains, mvc.mydomain.com and webforms.mydomain.com.

Anyone got any ideas on how to solve this? I have full access to the IIS 7.0.

(I have also tried turning SSL on the server off but i still get the same result)

Guide for authentication sharing: http://www.codeproject.com/KB/aspnet/SingleSignon.aspx

Updated I also tried this: (webforms .net 2.0)

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);

and in mvc 3 (.net 4)

FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(HttpContext.Request.Cookies["authcookie"].Value);
ViewBag.User = "User: " + ticket.Name;

This throws the following error: "Length of the data to decrypt is invalid."

Updated 6th jul

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

Patrick
  • 5,442
  • 9
  • 53
  • 104

2 Answers2

0

I think you have to set the machineKey in the Web.config of both application to the same value. You can generate a machinekey section here: http://aspnetresources.com/tools/machineKey

Wim
  • 1,967
  • 11
  • 19
  • They are the same, i triple checked that. – Patrick Jul 04 '11 at 12:29
  • ok another try. Set the domain to mydomain.com and not .mydomain.com – Wim Jul 04 '11 at 13:04
  • Have you tried setting up different domains in IIS Express (http://stackoverflow.com/questions/4709014/using-custom-domains-with-iis-express) to replicate the problem locally? – Wim Jul 05 '11 at 13:57
  • I have added 2 new domains in the IIS 7. Going to try with them first to see if i can get them to work. If that doesn't work then ill try it with IIS express. – Patrick Jul 06 '11 at 07:49
  • 1
    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. – Patrick Jul 06 '11 at 08:46
0

We could not find any ways of doing this so we had to convert our other project to use the .net 4 integrated app pool.

Patrick
  • 5,442
  • 9
  • 53
  • 104