有没有办法找出一个asp.net会议的年龄是多少? [英] Is there a way to find out the age of an asp.net session?

查看:195
本文介绍了有没有办法找出一个asp.net会议的年龄是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何找出多大一个asp.net(3.5)会话?

How do I find out how old an asp.net (3.5) session is?

推荐答案

不能直接我想,但它很容易做自己。在Global.asax中可以添加code将在session_start即使你加在创建会话时,告诉一个会话变量处理程序。

Not directly I think, but it would be easy to do it yourself. In global.asax you can add code to the Session_Start even handler where you add a session variable that tells when the session was created.

事情是这样的:

void Session_Start(object sender, EventArgs e) 
{
    // Code that runs when a new session is started
    Session["SessionStartTime"] = DateTime.Now;        
}

然后,你可以检查做在你的code以下多久会话已存在:

Then you can check how long the session has existed by doing the following in your code:

TimeSpan sessionLifeTime = DateTime.Now - (DateTime)Session["SessionStartTime"];

这篇关于有没有办法找出一个asp.net会议的年龄是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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