As the title states, I have a session variable that is set during a login script with asp and vb code-behind. Can I call a javascript function when a link is clicked that will destroy that session variable?
If it is possible, can I use jQuery to make that process easier?
As the title states, I have a session variable that is set during a login script with asp and vb code-behind. Can I call a javascript function when a link is clicked that will destroy that session variable?
If it is possible, can I use jQuery to make that process easier?
Share Improve this question asked Feb 27, 2009 at 16:10 AndersAnders 12.6k36 gold badges101 silver badges146 bronze badges4 Answers
Reset to default 4Yes, use $.post("logout.aspx");
in your Javascript, and create the file logout.aspx that destroys the session.
Server-side code (VB.NET in your case) is the only thing that can access the session and its variables. Your best bet is to create a WebService/WebMethod and use jQuery to call it.
This article should help you get started: Using jQuery to Consume ASP.NET JSON Web Services
Not explicitly - session variables live on the server, while Javascript operates in the client.
The best you can do is use JS to send a request to the server (possibly via Ajax), that will cause the server to delete the sesion variable.
Delete the ASP.NET Session cookie
document.cookie = 'ASP.NET_SessionId=xxx';