title: How to destroy session after clicking the logout button?
body: <p>I've read alot of problems about logout that it keeps going back to the recent page which is the account is still logged in, I have the same problem with <code>asp.net core mvc</code>, I've researched alot too, and I always see only <code>2014</code> answers and its <code>outdated</code>. I also wanted to destroy the the <code>Cookie Session</code> but this following codes are not working:</p>
  <pre><code>Session.Abandon();
  Session.Clear();
  </code></pre>
  <p>And when I transfer them to <code>HttpContext</code>, <code>Abandon()</code> can't be recognized</p>
  <pre><code>HttpContext.Session.Abandon();
  HttpContext.Session.Clear() //Not deleting the Session Cookie Also
  </code></pre>
  <p>Here is my code. In my controller:</p>
  <pre><code>public IActionResult logmeout()
      {
        
          HttpContext.Session.SetString(&quot;operator_name&quot;, &quot;&quot;);
          HttpContext.Session.SetString(&quot;reg_id&quot;, &quot;&quot;);
  
          HttpContext.Session.Remove(&quot;operator_name&quot;);
          HttpContext.Session.Remove(&quot;reg_id&quot;);
  
          HttpContext.Session.Clear();
          
          return RedirectToAction(&quot;Index&quot;, &quot;Home&quot;);
      }
  </code></pre>
  <p>All of them is not working and I tested it out one by one creating them as a comment, and it only redirect to the homepage. Anyone knows?</p>
  <p>EDIT:</p>
  <p>I forgot to add this  in <code>IActionResult</code></p>
  <pre><code>if (HttpContext.Session.GetString(&quot;operator_name&quot;) == &quot;&quot; || HttpContext.Session.GetString(&quot;reg_id&quot;) == &quot;&quot; || HttpContext.Session.GetString(&quot;operator_name&quot;) == null || HttpContext.Session.GetString(&quot;reg_no&quot;) == null)
  
          {
              return RedirectToAction(&quot;Index&quot;, &quot;Home&quot;);
          }
  </code></pre>
  <p>It also not working like this</p>
  <pre><code>public IActionResult logmeout()
      {
          if (HttpContext.Session.GetString(&quot;operator_name&quot;) == &quot;&quot; || HttpContext.Session.GetString(&quot;reg_id&quot;) == &quot;&quot; || HttpContext.Session.GetString(&quot;operator_name&quot;) == null || HttpContext.Session.GetString(&quot;reg_no&quot;) == null)
  
          {
              return RedirectToAction(&quot;Index&quot;, &quot;Home&quot;);
          }
  
  
          HttpContext.Session.SetString(&quot;operator_name&quot;, &quot;&quot;);
          HttpContext.Session.SetString(&quot;reg_id&quot;, &quot;&quot;);
  
          HttpContext.Session.Remove(&quot;operator_name&quot;);
          HttpContext.Session.Remove(&quot;reg_id&quot;);
  
          HttpContext.Session.Clear();
          
          return RedirectToAction(&quot;Index&quot;, &quot;Home&quot;);
      }
  </code></pre>