Daniel Starościk
Daniel Starościk

Reputation: 11

MVC 4 post automatically redirect to action that i dont want

I have a problem with ASP.NET MVC 4 application. I have a partial view with fallowing code:

<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>

And after i click "Log out" im redirected to: /Account/Login?ReturnUrl=%f2Account%f2LogOff and going to action:

//
// GET: /Account/Login

[AllowAnonymous]
public ActionResult Login()
{
    ViewBag.Title = loginTitle;
    return View();
}

But i want to handle this in action:

[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult LogOff()
{
    Session["user"] = null;
    return RedirectToAction("Index", "Index");
}

Can you help me?

Upvotes: 0

Views: 290

Answers (1)

romanoza
romanoza

Reputation: 4862

It looks like you are not logged in during logging off.

Upvotes: 1

Related Questions