会话超时Asp.net中的问题......请帮忙 [英] Session Time out Problem in Asp.net......Please help

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

问题描述

你好朋友,



祝大家有个美好的一天。



遇到会话麻烦超时。

----------------------------------



我在Asp.net c#,Sql Server 2005中创建了一个Web应用程序。



但我遇到会话超时问题。



我的第一页是login.aspx,此页面用于访问/打开应用程序。


$ b用户登录后,如果他/她的用户名和密码正确,则为$ b。它将重定向到主页面,在这里他将看到/访问所有网页。



假设,如果我在这个应用程序上闲置一段时间....它显示错误。



这就是错误......



====== ================================================== =========



对象引用未设置为对象的实例。



描述:执行当前Web请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。



异常详细信息:System.NullReferenceException:对象引用未设置为对象的实例。



来源错误:





第18行:lblDate.Text = System.DateTime.Now.ToLongDateString();

第19行:lblTime.Text = System.DateTime.Now.ToShortTimeString();

第20行:lblWelcomeMSG.Text = Session [UserName]。ToString();

第21行:}

第22行:}



=============== ================================================== ===



请帮帮我,建议我,如何解决这个问题。



谢谢提前。

解决方案

你可以增加超时,但你不应该这样做。

要增加它,请看这里: http://msdn.microsoft.com/en-us/library/h6bb9cz9(vs .80).aspx [ ^ ]

但是你应该优雅地通过检查或者使用try ... catch块来处理会话超时。

哦,顺便说一句,从来没有读过两次日期和时间 - 阅读一次,将其存储在变量中,然后使用两次:

 尝试 
{
DateTime now = System.DateTime.Now;
lblDate.Text = now.ToLongDateString();
lblTime.Text = now.ToShortTimeString();
lblWelcomeMSG.Text = Session [ UserName]。ToString();
...
}
catch (例外情况)
{
// 记录它,或向用户报告他需要再次登录。
}


Hello FRIENDS,

Have a good day all of you.

Facing trouble with session timeout.
----------------------------------

I have created a web application in Asp.net c#, Sql Server 2005.

but am facing a problem with session timeout.

my first page is login.aspx, this page is used to access/open the application.

after user login, if his/her username and password is correct. it will redirect to the main pages, here he will see/access all the webpages.

Suppose, if i stay idle for some time on this application....it shows an error.

THIS IS THE ERROR...

=================================================================

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:


Line 18: lblDate.Text = System.DateTime.Now.ToLongDateString();
Line 19: lblTime.Text = System.DateTime.Now.ToShortTimeString();
Line 20: lblWelcomeMSG.Text = Session["UserName"].ToString();
Line 21: }
Line 22: }

====================================================================

Please help me and SUGGEST me, how to solve me this problem.

Thanks in Advance.

解决方案

You can increase the timeout, but you shouldn''t have to.
To increase it, see here: http://msdn.microsoft.com/en-us/library/h6bb9cz9(vs.80).aspx[^]
But you should cope with the session timing out gracefully, by checking, or by using a try...catch block.
Oh, and by the way, never read the date and time twice - read it once, store it in a variable, and use it twice instead:

try
   {
   DateTime now = System.DateTime.Now;
   lblDate.Text = now.ToLongDateString();
   lblTime.Text = now.ToShortTimeString();
   lblWelcomeMSG.Text = Session["UserName"].ToString();
   ...
   }
catch (Exception ex)
   {
   // Log it, or report to the user that he needs to log in again.
   }

If you read twice, you can get different days, months, or even years and this can cause subtle bugs which are hard to track down. In this case, it just presents a bad date and time combo to the user, but if you use similar code for databases you can truly mess up your data!


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

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