I have MVC application configured to use Forms Authentication. I’m signing out users by calling LogOff action
public ActionResult LogOff()
{
FormsAuthentication.SignOut();
DropUserInfo();
return RedirectToUrl(null, "Home", "Index", null);
}
But everytime code reaches to FormsAuthentication.SingOut() line, applications throws an exception
Server cannot modify cookies after HTTP headers have been sent
What error message says is pretty clear, thou I can’t understand, how is that possible that Http headers have been sent while calling FormsAuthentication.SingOut() method.
So the question is what causes the error, and how to solve this ?
I’ve initiated Redirect() method call, before calling LogOff() function in ActionFilter, which cased the error to be thrown.
Hope this will help someone else.