是否有任何适当的解决方案在客户端清除服务器端的会话? [英] Is there is any appropriate solution to clear server side session on client side?

查看:132
本文介绍了是否有任何适当的解决方案在客户端清除服务器端的会话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有适当的方法在客户端清除服务器端的会话。
我使用Java脚本来清除会话,但在以往的网页会被重定向然后服务器端的会话值将清除,即使在不火这里的单击事件是一个java脚本code,我对李的ONCLICK

 <脚本类型=文/ JavaScript的>
     功能Clear_(){         '<%=会话[UID] =%GT;';当过的页面将被重定向//仅此行执行。         警报('OK');
     }
  < / SCRIPT>


解决方案

为什么出现这种情况的原因是当页面正在被解析,它总是寻找服务器端的标签和第一个执行它。它作为解析服务器端控件一样。所以,即使你写了code,火上的任何按钮的点击事件中,code将执行每次其加载。
即使你试评在服务器标签中的code时,code会被执行。


  


       功能Clear_(){

  //'<%=会话[UID] =%GT;'; //这还行执行     警报('OK');
 }< / SCRIPT>


回答你的问题是即可。会话存储为服务器端,那么你怎么可以清除它核素的一面。你必须让AJAX请求到服务器,并在服务器上清除会话

更新2

其作为aspx页面同样被解析的服务器控件。这些服务器标记需要被处理,而请求是在服务器上,然后进行评价的值。例如,如果你想在JavaScript的一些价值从服务器上的某些会话值进行填充。


  

//在JavaScript结果
  VAR myvalue的= LT;%=会话[SomeVal]%>


所以,当网页被解析,服务器标签中的价值进行评估,并结合各自实际值替换(用于控制,它与HTML代替)。所以在最终输出,发送到客户端,下面的标记将被发送


  

//在JavaScript结果
  VAR myvalue的= 50;


您可以通过浏览器看在查看源文件验证。

Is there any appropriate method to clear a server side session on client side. I use java script to clear a session, but when ever a page is redirected then server side session value will clear, even when the click event in not fire here is a java script code which I call on ONCLICK of LI

<script type="text/javascript">
     function Clear_() {

         '<%=Session["UID"]=""%>';// only this line executes when ever the page is redirected.

         alert('ok');
     }
  </script>

解决方案

The reason why this happens is while page is being parsed, it always looks for the server side tags and execute it first. Its same as parsing server side control. So even if you have written the code, to fire on click event of any button, the code would execute every time its loaded. Even if you try to comment the code in server tag, the code would be executed.

function Clear_() {

    // '<%=Session["UID"]=""%>';// still this line executes

     alert('ok');
 }   </script>

The answer to your problem is NO. The sessions are stored as server side, then how could you clear it clide side. You have to make AJAX request to server and clear the session on server

UPDATE 2

Its same as the aspx page is parsed for server control. These server tags need to be processed while the request is at server and then evaluated the value. For example, if you want some value in javascript to be populated from some session value on the server.

//in javascript
var myValue = <%= Session["SomeVal"] %>

So when the page is parsed, the value inside server tags are evaluated and replaced with their actual value(For control, its replaced with html). So in the final output, that is sent to client, the following markup would be sent

//in javascript
var myValue = 50;

You could verify by looking in the "View Source" from the browser.

这篇关于是否有任何适当的解决方案在客户端清除服务器端的会话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆