Session is not clearing after signing out from application razor pages

Blooming Developer 276 Reputation points
2023-01-31T04:04:24.65+00:00

Hi,

I want to clear my sessions,once i logout from my application.

Now when i logout from application and click the back button,its navigating to the previous page.

My logout button is given as a menu in _Layout page like this

<li class="nav-item">
    <a class="nav-link" asp-page="/logout">
       <i class="fas fa-sign-out-alt nav-icon white"></i>
       <p>
          SIGN OUT
       </p>
     </a>
</li>

Logout.cshtml

<div class="row m-3">
    <div class="col-4"></div>
    <!--JUMBTRON STARTS HERE-->
    <div class="col-4">
        <div class="jumbotron text-center" style="margin-top:225px;">
            <div style="font-size:larger;font-family:Delivery;"><b>You have successfully logged out.</b></div>
            <div style="font-size:larger;font-family:Delivery;"><b>Please <a asp-page="/Login">click here</a> to login to the portal.</b></div>
        </div>
    </div>
    <!--JUMBTRON ENDS HERE-->
    <div class="col-4"></div>
</div>

Logout.cshtml.cs

public class LogoutModel : PageModel
    {
        public void OnGet()
        {
            HttpContext.Session.Clear();
        }

        public IActionResult OnPostSignOut()
        {
            
            string rootPath = Url.Content("~");
            return Redirect(rootPath + "/Login");
        }
    }

I am clearing the session when the logout page is loaded. Is there anything i am missing?

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,199 questions
{count} votes