2016-02-16

MVC Logoff does not work after updating Identity to 2.2

It looks like development world is becoming more and more addicted to packages. In Visual Studio we use Nuget to manage packages.

At first sight packages are great. You can use only what you need. You can easily update or remove only selected components. But in real world projects opening Nuget is scarry. You know that anxious feeling when you see a list of new versions of packages you use? Should I upgrade?

And when you decide to do so... Well, if you are lucky, some things will not work anymore. If you are less lucky, you will be changing a lot of code and after some time revert the old version back.

This happened when I have updated Identity from 2.1.0 to 2.2.0 in one of my projects. I felt possitive because there were no errors after the upgrade. Wow. It just works!

I was happy util I tested the application and noticed that user cannot logout anymore. Why!?

I have looked at the controller action responsible for logoff:
public ActionResult LogOff()
{
    AuthenticationManager.SignOut();
    return RedirectToAction("Index", "Home");
}
To resolve this you have to change AuthenticationManager line to:
AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
Now your users can logoff.

No comments:

Post a Comment