title: ASP.net 2.2 MVC: Logout
body: <p>I have a simple login-logout system, and don't use any areas, all Views are in the folder views.</p>
  
  <p><a href="https://i.stack.imgur.com/DjiTf.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DjiTf.jpg" alt="Solution treeview"></a></p>
  
  <p>I was trying to logout with this function in my view, but that brings me to the <code>localhost:port/Account/logout</code> page, without passing my logout function in the AccountController.</p>
  
  <pre><code>&lt;a class="" asp-area="" asp-controller="Account" asp-action="Logout"&gt;Logout&lt;/a&gt;
  </code></pre>
  
  <p>A google search brought me to a logout form, but I need to call the <strong><code>Identity</code></strong> area to get it to work.</p>
  
  <pre><code>&lt;form asp-area="Identity" asp-page="/Account/Logout" asp-route-returnUrl="@Url.Action("Index", "Home", new { area = "" })" method="post" id="logoutForm" class="ml-auto"&gt;
      &lt;ul class="nav navbar-top-links navbar-right"&gt;
          &lt;li&gt;&lt;button type="submit" class="fa fa-sign-out btn btn-w-m btn-link"&gt;Logout&lt;/button&gt;&lt;/li&gt;
      &lt;/ul&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>I find that very strange, because I don't have that area.
  My AccountController has a simple standard logout function, but I never get there.</p>
  
  <pre><code>[HttpPost]
  [ValidateAntiForgeryToken]
  public async Task&lt;IActionResult&gt; Logout()
  {
      await _signInManager.SignOutAsync();
      _logger.LogInformation("User logged out.");
      return RedirectToAction(nameof(HomeController.Index), "Home");
  }
  </code></pre>
  
  <p>Does anyone knows why I don't get there, all my other functions pass the AccountController: Login, Register, forgot password, .... It's only the Logout that I can't figure out.</p>
  
  <p>And is it possible with a simple <code>&lt;a&gt;</code> link or do I have to use the form method?</p>