Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
AI OnAI Off
Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
Thanks David, I stumbled across this and initially think it wasn't very helpful but it ultimately did solve my problem. Essentially, I needed to add virtual to the Logout() action result, which fixed the 404 issue. Hope this at least helps someone else in the future! Here's the correct method signature:
[HttpPost]
[ValidateAntiForgeryToken]
public virtual ActionResult Logout()
{
// Log user out
// Redirect
return Redirect("/");
}
I have the following form being rendered from within a block.
@using (Html.BeginForm("Logout", null, new { language = ContentLanguage.PreferredCulture.Name }, FormMethod.Post)) { @Html.AntiForgeryToken(); <button type="submit">Log Out</button> }
Here's the controller:
public class HeaderBlockController : BlockController<HeaderBlock> { [HttpGet] public override ActionResult Index(HeaderBlock currentBlock) { var model = new HeaderBlockViewModel(currentBlock); return PartialView("Blocks/HeaderBlock", model); } [HttpPost] [ValidateAntiForgeryToken] public ActionResult Logout() { // Log user out // Redirect return Redirect("/"); } }
When I submit the form, the page 404s and does not actually execute the Logout() method. What am I missing? Should I be approaching this differently?