惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
Darknet – Hacking Tools, Hacker News & Cyber Security
V
Vulnerabilities – Threatpost
Cloudbric
Cloudbric
G
GRAHAM CLULEY
S
Securelist
Schneier on Security
Schneier on Security
Help Net Security
Help Net Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Project Zero
Project Zero
Spread Privacy
Spread Privacy
P
Privacy International News Feed
C
Cyber Attacks, Cyber Crime and Cyber Security
Cisco Talos Blog
Cisco Talos Blog
T
Tailwind CSS Blog
博客园_首页
有赞技术团队
有赞技术团队
Simon Willison's Weblog
Simon Willison's Weblog
Stack Overflow Blog
Stack Overflow Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Latest news
Latest news
T
Tor Project blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Attack and Defense Labs
Attack and Defense Labs
www.infosecurity-magazine.com
www.infosecurity-magazine.com
O
OpenAI News
J
Java Code Geeks
T
Tenable Blog
K
Kaspersky official blog
AWS News Blog
AWS News Blog
S
Security @ Cisco Blogs
The GitHub Blog
The GitHub Blog
T
Threatpost
月光博客
月光博客
H
Heimdal Security Blog
Security Latest
Security Latest
The Hacker News
The Hacker News
Y
Y Combinator Blog
A
Arctic Wolf
Apple Machine Learning Research
Apple Machine Learning Research
C
Cisco Blogs
美团技术团队
Microsoft Security Blog
Microsoft Security Blog
Hugging Face - Blog
Hugging Face - Blog
T
The Blog of Author Tim Ferriss
C
CERT Recently Published Vulnerability Notes
D
Docker
Google Online Security Blog
Google Online Security Blog
D
DataBreaches.Net
V
Visual Studio Blog
H
Help Net Security

博客园 - Easy Company

如何取得显示实现方法的MethodInfo SQL Server 2008中许多兼容性上的问题 Mock 对象何时使用? ThreadPool 在.Net 2.0 SP1中的部分变化可能会让你的程序停止工作 目前不能使用SQL Server 2008 CTP February 2008存储Team Foundation Server 2008的数据 Javascript操作在各浏览器下的性能比较 WCF Web 编程模型资源 代码行数引起的思考 在按钮点击后禁用它直到操作完成 - Easy Company - 博客园 ASP.NET 2.0中使用强类型访问PreviousPage属性页的控件 Silverlight 与 Microsoft ASP.NET Futures (July 2007) 更新 VS 2008 和.NET 3.5 Beta 2 安装注意事项 Partial Methods CIL(Common Intermediate Language)指令集 刚刚下载了 Visual Studio 2005 Service Pack 1 (SP1) .Net 中的日志 使用 Membership 时获取用户的最后登录时间 How To 推荐用于 AJAX 页面的进度指示器图片
使用 Facade 设计模式管理 ASP.Net Session 变量
Easy Company · 2006-12-06 · via 博客园 - Easy Company

ASP.NET 提供了 HttpSessionState 类用来存储 session-state 的值。每一个 HTTP 请求都包含一个 HttpSessionState 类的实例,可以通过 HttpContext.Current.Session 属性来获取。

在开发中对 Session 进行集中管理,更便于维护和修改。这里给出一个使用 Facade 设计模式管理 ASP.Net Session 变量的示例。

 1 using System;
 2 using System.Web;
 3 
 4 /// <summary>
 5 /// SessionManager 的摘要说明
 6 /// </summary>
 7 public static class SessionManager
 8 {
 9     private const string OWNED_ENTERPRISE = "Enterprise";
10     private const string START_DATE = "StartDate";
11     private const string STOP_DATE = "StopDate";
12 
13     /// <summary>
14     /// 获取当前用户名称
15     /// </summary>
16     public static string Username
17     {
18         get { return HttpContext.Current.User.Identity.Name; }
19     }
20 
21     /// <summary>
22     /// 获取或设置当前用户所属企业的信息。
23     /// </summary>
24     public static Enterprise OwnedEnterprises
25     {
26         get
27         {
28             Enterprise result =
                    (Enterprise)HttpContext.Current.Session[OWNED_ENTERPRISE];
29 
30             if (result == null)
31             {
32                 result = Enterprise.GetEnterprise (Username);
33                 OwnedEnterprises = result;
34             }
35 
36             return result;
37         }
38         private set
39         {
40             HttpContext.Current.Session[OWNED_ENTERPRISE] = value;
41         }
42     }
43 
44     /// <summary>
45     /// 获取或设置业务开始时间
46     /// </summary>
47     public static DateTime StartDate
48     {
49         get
50         {
51             if (HttpContext.Current.Session[START_DATE] == null)
52                 return DateTime.MinValue;
53             else
54                 return (DateTime)HttpContext.Current.Session[START_DATE];
55         }
56         set { HttpContext.Current.Session[START_DATE] = value; }
57     }
58 
59     /// <summary>
60     /// 获取或设置业务停止时间
61     /// </summary>
62     public static DateTime StopDate
63     {
64         get
65         {
66             if (HttpContext.Current.Session[STOP_DATE] == null)
67                 return DateTime.MaxValue;
68             else
69                 return (DateTime)HttpContext.Current.Session[STOP_DATE];
70         }
71         set { HttpContext.Current.Session[STOP_DATE] = value; }
72     }
73 }
74