asp.net中的会话问题 [英] session problem in asp.net

查看:67
本文介绍了asp.net中的会话问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在asp.net中遇到会话问题。



我有第一页登录此网络应用程序。登录后我拿了标签显示登录的用户名。



i在主页cs文件中写了这段代码.... bcoz在每个页面显示标签。<如果应用程序闲置一段时间,请在登录后获得
...然后每当我点击菜单链接时。这是它显示的错误。

facing problem with session in asp.net.

I have a first page as login to this web appl. after logged in i took label to display username who logged in.

i wrote this code in master page cs file....bcoz to show label in every page.
after login if the application is idle for sometime...then whenever i clicks menu link. This is the error it shows.

protected void Page_Load(object sender, EventArgs e)
    {
         lblUser.Text = Session["UserName"].ToString();
}



任何人都可以帮助我。谢谢。


can anybody help me. thank you.

推荐答案

更改代码以处理错误情况:

Change your code to handle the error case as:
protected void Page_Load(object sender, EventArgs e)
{
   if(Session["UserName"] != null)
     lblUser.Text = Session["UserName"].ToString();
   else
     Response.Redirect("SessionTimeoutMessagePage.aspx");
}


引用 - HYD说:
Quote - HYD says:

..如果应用程序闲置一段时间......

... if the application is idle for sometime ...

你的问题可能是会话超时

在这种情况下你应该恢复你的会话参数和在任何情况下,如果会话参数存在,或者会话存在,你最好使用会话参数检查。



会话[ mySessParam] == null

如果以上是 True ,则表明会话已经结束(或者代码中的某个地方)已经删除了参数。



注意:
您可以配置会话超时 web.config文件超过默认的20分钟。



干杯,

Edo

Your problem is probably that the session timed out.
In this case you should revive your session parameters and in any case you''d better use a check for the session parameter if it exists, or if the session exists.

Session["mySessParam"] == null
If the above is True, it indicates that the session has ended (or that somewhere in your code you''ve removed the parameter).

NOTE:
you can configure the session timeout in your web.config file to be more than the default 20 mins.

Cheers,
Edo


引用:

如果应用程序闲置一段时间

if the application is idle for sometime





正如Edo Tzumer所说问题似乎是会话timeoutout。你可以从web.config维护你的会话时间。



类似的事情可以通过配置< b> IIS 上的会话状态设置,您可以在其中简单地输入会话超时时间或为您的应用选择更合适的会话模式。



As stated by Edo Tzumer your problem seems to be of session time-out.You can maintain your session time out from web.config.

Similar thing can be done more easily by configuring the session state settings on your IIS where you can simply put in the session time out time or select the more appropriate session mode for your application.


这篇关于asp.net中的会话问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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