超时asp.net给出错误
问题描述:
当用户在网站上登录时,他可以做他想做的事(这是正确的)。但是如果他离开几分钟,会发生一些time-out
。这导致以下错误:超时asp.net给出错误
Object reference not set to an instance of an object.
他thros本上显示的用户名会话:
Label1.Text = "Welkom " + Session("Naam").ToString()
关于如何解决它的任何想法?或者如何正确显示它?
答
你有两个选择;
增加会话超时。所以,当你创建会话的时候,你可以设置超时时间。
Session.Timeout = 30;
或者设置超时在web.config
<configuration>
<system.web>
<sessionState timeout="20"></sessionState>
</system.web>
</configuration>
或者你也可以检查,以确保该会话值存在。
C#
if (Session["Naam"] != null){ ... }
vb.net
If Not Session("Naam") Is Nothing Then