I have a method ActionResult
which has a cycle for
where I go through all the cookies
to eliminate them when doing logout. The problem is that when I call the method from my view (This through a form
) I enter the method but I never finish leaving the cycle for
esoy in a loop and I do not know why. The counter at the time of entering tells me that there are x cookies
but at the time of going through them I will add one more to the counter of for
and never dread never leaving.
My code:
[HttpPost]
[ValidateAntiForgeryToken]
[Route("account/exit")]
public RedirectResult LogOff()
{
for (int i = 0; i < Request.Cookies.Count; i++)
{
var cookie = new HttpCookie(HttpContext.Request.Cookies[i].Name);
cookie.Expires = DateTime.Now.AddDays(-1);
cookie.Value = string.Empty;
Response.Cookies.Add(cookie);
}
Session.Abandon();
return Redirect("miurl");
}
From my view I have the following:
@using (Html.BeginForm("LogOff", "Account", FormMethod.Post, new { id = "logoutForm" }))
{
@Html.AntiForgeryToken()
<li><a href="javascript:document.getElementById('logoutForm').submit()">Cerrar sesión</a></li>
}