最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Is it possible to destroy a session variable set by ASP.NET (VB.NET) with Javascript? - Stack Overflow

programmeradmin2浏览0评论

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 badges
Add a ment  | 

4 Answers 4

Reset to default 4

Yes, 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';
发布评论

评论列表(0)

  1. 暂无评论