日期:2014-05-18  浏览次数:20401 次

如何在自定义的类中取得Session
用户上传文件到以自己的用户名为文件夹名的文件夹中。
用户的登录信息保存在Session中。
文件保存操作在一个自定义的类 XXSaver中。
现在的问题是。
如何在XXSaver中取得Session得值?
(因为XXSaver是通过Factory对象创建出来的。所以不想通过传递参数的方法)


------解决方案--------------------
C# code
     System.Web.HttpContext.Current.Session["Name"]

------解决方案--------------------
/// <summary>
// /// 判断session过期。
// /// </summary>
// /// <returns></returns>
// public static bool SessionTimeOut()
// {
// HttpContext p = HttpContext.Current;
// if (p.Session["ygdm"] == null)
// {
// p.Response.Write("会话超时,请重新<a target='_top' href='../common/login.aspx'>登录</a>。");
// p.Response.End();
// return true;
// }
// return false;
// }