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

推荐订阅源

GbyAI
GbyAI
J
Java Code Geeks
雷峰网
雷峰网
WordPress大学
WordPress大学
宝玉的分享
宝玉的分享
云风的 BLOG
云风的 BLOG
V
Visual Studio Blog
V
Vulnerabilities – Threatpost
S
Securelist
The Hacker News
The Hacker News
The Register - Security
The Register - Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Help Net Security
Help Net Security
G
Google Developers Blog
Hugging Face - Blog
Hugging Face - Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
M
MIT News - Artificial intelligence
AI
AI
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
The GitHub Blog
The GitHub Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Schneier on Security
Schneier on Security
N
Netflix TechBlog - Medium
T
The Blog of Author Tim Ferriss
Google DeepMind News
Google DeepMind News
Hacker News - Newest:
Hacker News - Newest: "LLM"
H
Hacker News: Front Page
博客园 - 司徒正美
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
B
Blog
Microsoft Azure Blog
Microsoft Azure Blog
大猫的无限游戏
大猫的无限游戏
Security Latest
Security Latest
Engineering at Meta
Engineering at Meta
N
News and Events Feed by Topic
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
酷 壳 – CoolShell
酷 壳 – CoolShell
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
T
Threat Research - Cisco Blogs
U
Unit 42
V
V2EX
V2EX - 技术
V2EX - 技术
L
LINUX DO - 最新话题
aimingoo的专栏
aimingoo的专栏
Microsoft Security Blog
Microsoft Security Blog
Recorded Future
Recorded Future
P
Privacy & Cybersecurity Law Blog
美团技术团队
小众软件
小众软件
F
Fortinet All Blogs

博客园 - 昊子

工作流参考模型(Workflow Reference Model) DNN default document的异常错误 如何使用GoogleCode提供的SVN Source Control服务 Norton PartitionMagic 8.0 Resizing Boot Partition 智能提示和那些值得崇拜的人 推荐一个Flex & AIR皮肤站点 Flex locale Flex Repeater 多层嵌套 从没走远 SubmitMask 1.0 发布 如何获取Footer中的子控件 DNN学习笔记 之一 配置 使用NHibernate时产生的一个错误 NHibernate官方文档 之 NHibernate指南-前言 C#反转单向链表 C#事件编程 静态构造函数和静态成员变量初始化的调用时间 NHibernate和SqlImage 结束无谓的讨论吧
SessionDiskCache 0.1版发布
昊子 · 2007-07-10 · via 博客园 - 昊子

What:
SessionDiskCache 是一个在Asp.net中可插接使用的HttpModule,SessionDiskCache支持asp.net2.0,不支持asp.net1.0和asp.net1.1
Why:
通常在我们对系统进行维护时(或其他意外情况)可能导致用户Session丢失,为了尽量减少此时的损失于是产生了SessionDiskCache
How:
SessionDiskCache在程序结束时将Session序列化到磁盘,程序重新开始时有新会话建立则检查是否有同一SessionID的文件,并将内容重新加载到Session
理论上使用SessionDiskCache无需对程序进行任何改动,但你需要为SessionDiskCache提供保存功能的类增加可序列化标签
Where:
SessionDiskCache可以用在个人站点,网站或企业级asp.net应用程序中

预备知识:
HttpModule
Session inproc
.net Serialization

如何安装:
一、把编译好的PBLee.WebUtil.SessionDiskCache.dll复制到web发布bin文件夹下
二、修改web.config

<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
    
<configSections>
        
<section name="SessionDiskCache" type="PBLee.WebUtil.SessionDiskCache.SessionDiskCacheConfigurationSectionHandler, PBLee.WebUtil.SessionDiskCache"/>
    
</configSections>
  
<!-- Path 设置保存Session序列文件保存路径 ~\使用当前站点相对路径 -->
    
<SessionDiskCache Path="~\SessionCache"/>
    
<system.web>
        
<httpModules>
            
<add type="PBLee.WebUtil.SessionDiskCache.SessionDiskCache, PBLee.WebUtil.SessionDiskCache" name="SessionDiskCache"/>
        
</httpModules>

    
</system.web>
</configuration>


三,为可以在SessionDiskCache中保存的类增加可序列化标签[Serializable]

[Serializable]
public class LoginUser

完成

SessionDiskCache如何工作:
作为HttpModule监听Session_Start Session_End Application_End事件

                sessionModule.Start +=new EventHandler(SessionDiskCache_SessionStart);

                sessionModule.End 
+=new EventHandler(SessionDiskCache_SessionEnd);

                context.Disposed 
+=new EventHandler(context_ApplicationEnd);

Session开始时检查是否有已序列到磁盘的Session对象

private void SessionDiskCache_SessionStart(object sender, EventArgs e)
        
{
            HttpSessionState session 
= HttpContext.Current.Session;
            session[
"SessionID"= session.SessionID;
            SessionList.Add( session );
            LoadSession( session );
        }

Application停止时将所有Session保存到磁盘

private void context_ApplicationEnd(object sender, EventArgs e)
        
{
            
foreach ( System.Web.SessionState.HttpSessionState session in SessionList )
            
{
                SaveSession( session );
            }

        }

注意:
SessionDiskCache只能用于可捕获Application_End的情况,如bin文件夹变动,web.config变动,IIS停止
如果您准备使用SessionDiskCache,请尽量了解前面提到的预备知识,已备在需要修改时有能力独立完成。
本工具以免费开放源代码方式提供,不保证提供技术支持和版本更新
相关技术讨论可以在本Blog(http://pblee.cnblogs.com)进行

源代码和Sample 点击这里下载