简体   繁体   English

检查会话是否存在,如果没有在VB.Net中创建新会话

[英]Checking whether a Session exists, if not creating a new session in VB.Net

I'm new to this so I'm having a difficult time figuring this thing. 我对此并不陌生,所以我很难解决这个问题。

I have a ASP.Net application which has two controls, 'lblSessionState' which has a value - "There is no session" 我有一个具有两个控件的ASP.Net应用程序, “ lblSessionState”具有一个值-“没有会话”
'btnSessionState' which has a value - "Start Session" 具有值的“ btnSessionState” -“开始会话”

What i want to know is how to check whether a Session exists. 我想知道的是如何检查会话是否存在。 For example, how do I check whether there is a Session called "MySession" and if that exists how to assign its value to 'lblSessionState' as text value. 例如,如何检查是否存在一个名为“ MySession”的会话,以及是否存在将其值分配给“ lblSessionState”作为文本值的方法。

If "MySession" does not exist how do I create it and assign a value. 如果“ MySession”不存在,如何创建它并分配一个值。

Also I want to know when a button is clicked how to detect the post back and clear the session. 我也想知道单击按钮时如何检测回发并清除会话。

Thank you so much in advance..... 提前非常感谢您.....

HYG HYG

if(Session["MySession"]==null)
    Session["MySession"] = "Your value";

lblSessionState.Text = Session["MySession"].ToString();

check the following link for more details http://www.w3schools.com/asp/asp_sessions.asp 检查以下链接以获取更多详细信息http://www.w3schools.com/asp/asp_sessions.asp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM