I have an intranet project written in MVC 4 which uses Windows Authentication to authorise and authenticate users.
I need to add a \'Login as another user\' function
This method will always log the user out and redirect to the home page. I also added [AllowAnonymous] to make sure everybody can access this method.
[AllowAnonymous]
public ActionResult LogOut()
{
HttpCookie cookie = Request.Cookies["TSWA-Last-User"];
cookie = new HttpCookie("TSWA-Last-User", string.Empty)
{
Expires = DateTime.Now.AddYears(-5)
};
Response.Cookies.Set(cookie);
Response.AppendHeader("Connection", "close");
Response.StatusCode = 401; // Unauthorized;
Response.Clear();
// redirect to home
Response.Write("");
Response.End();
return RedirectToAction("Index");
}