我对 ASP.NET MVC 4 应用程序有疑问。我对闲置代码有部分看法:
<li>@using (Html.BeginForm("LogOff", "Account", FormMethod.Post,
new { id = "logoutForm", style = "display: inline;" }))
{
@Html.AntiForgeryToken()
<a href="javascript:document.getElementById('logoutForm').submit()">Log out</a>
}
</li>
在我点击“注销”后,我被重定向到:/Account/Login?ReturnUrl=%f2Account%f2LogOff 并开始行动:
//
// GET: /Account/Login
[AllowAnonymous]
public ActionResult Login()
{
ViewBag.Title = loginTitle;
return View();
}
但我想在行动中处理这个:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult LogOff()
{
Session["user"] = null;
return RedirectToAction("Index", "Index");
}
你能帮助我吗?