views:

1471

answers:

4

As the title states, I have a session variable that is set during a login script with asp.net and vb.net 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?

+1  A: 

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.

Visage
+2  A: 

Yes, use $.post("logout.aspx"); in your Javascript, and create the file logout.aspx that destroys the session.

svinto
+1  A: 

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

Chris Zwiryk
+1  A: 

Delete the ASP.NET Session cookie

document.cookie = 'ASP.NET_SessionId=xxx';
Dead account
I think he's just looking to delete a specific session variable, not abandon the whole session.
tlianza