Click here to Skip to main content
15,888,803 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I Have a problem with my project ,


I cannot clear session after log out ,

What I have tried:

this is my code

<div class="modal-footer">
         <button class="btn btn-secon dary" type="button" data-dismiss="modal">Cancel</button>
         <a class="btn btn-primary" onClick="reload()">Logout</a>
       </div>


<script type="text/javascript">
      function reload() {
          window.location = "../Login.aspx";
          Session["LogedUserID"] = null;
      }
 </script>


how can i solve this?
Posted
Updated 26-Apr-20 22:23pm
Comments
F-ES Sitecore 27-Apr-20 10:45am    
Put Session.Abandon() in the Page Load event of login.aspx, you can't use it in javascript like that.
Member 14760154 28-Apr-20 0:59am    
i have try like this,
but it's still does not work

this is my updated code


function reload() {
//Session["LogedUserID"] = null;
window.location = "../Login.aspx";
Session.Abandon();
//document.cookie.split(";").forEach(function (c) {
//document.cookie = c.replace(/^ +/, "").replace(/=.*/, "=;expires=" + new Date().toUTCString() + ";path=/");
//});
}

1 solution

As you are doing this in ASP Web Forms, you should really use Session.Abandon(); to clear the session. As the name implies, this abandons the session and implicitly creates a new session for the user. You should do this in code behind.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900