Cookie authentication not working on IIS 8.5

Sep 27, 2016 at 9:50 AM
I have developed an ASP.NET webapp with OWIN authentication, which works fine on my development machine (Windows 10/IIS 10), but when the webapp is published to my Windows 2012 server with IIS 8.5, the cookie authentication does not seem te work.

When I login (with the IsPersistent setting to true) and close the browser, I am still logged on when I start my browser again, so that's OK. But when I restart IIS and startup the browser, I have to logon again.

I have created a very simple application to test this, with the following code:

Startup.cs
public void ConfigureAuthentication(IAppBuilder app)
    {
        app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
            LoginPath = new PathString("/Login"),
            CookieName = "ThisIsTheAuthCookie"
        });
    }
AuthenticationController.cs
public ActionResult Login(string userName, string password)
    {
        //For testing purposes every user/pwd is fine
        var identity = new ClaimsIdentity(new [] { new Claim(ClaimTypes.Name, userName), },
            DefaultAuthenticationTypes.ApplicationCookie,
            ClaimTypes.Name, ClaimTypes.Role);

        HttpContext.GetOwinContext().Authentication.SignIn(new AuthenticationProperties { IsPersistent = true }, identity);

        return RedirectToAction("index", "home");
    }
Even Chrome shows the cookie, but it looks like OWIN is not using it on IIS 8.5:
Image

Does anybody have an idea what the problem is?

Thx, Danny
Oct 3, 2016 at 10:01 PM
The problem is solved. I had to add the MachineKey element in the web.config!
Marked as answer by scheelings on 10/3/2016 at 3:02 PM