I'm using windows login in asp.net to login in users however when it comes to the logoff it not working so properly. When click close it takes me to the HTTP Error 401.2 - Unauthorized page if I click cancel it gives me this Unauthorized. Reload the page to try again... Is there a way I could just redirect the user or give them a link to click so it brings them back to home page. And if I sign in as the same user that was logged in before the pop up box continues to show until I enter another user. So what if the same user wants to login again? I have done some research but nothing seems to work.
public ActionResult SignInAsDifferentUser()
{
HttpCookie cookie = Request.Cookies["TWCL-Last-User"];
if (User.Identity.IsAuthenticated == false || cookie == null || StringComparer.OrdinalIgnoreCase.Equals(base.User.Identity.Name, cookie.Value))
{
string name = string.Empty;
if (Request.IsAuthenticated)
{
name = this.User.Identity.Name;
}
cookie = new HttpCookie("TWCL-Last-User", name);
Response.Cookies.Set(cookie);
Response.AppendHeader("Connection", "close");
Response.StatusCode = 401;
Response.Clear();
Response.Write("Unauthorized. Reload the page to try again...");
Response.End();
return RedirectToAction("SignInAsDifferentUser");
}
cookie = new HttpCookie("TWCL-Last-User", string.Empty)
{
Expires = DateTime.Now.AddYears(-5)
};
base.Response.Cookies.Set(cookie);
return RedirectToAction("Index");
}