设为首页 加入收藏 网站首页
休闲娱乐
军事·社会百态·娱乐八卦·校园
体育·美女写真·幽默笑话·游戏
综合·在线视频·搞笑图片·灵异
两性生活
两性知识·性爱技巧
情色实录·两性图片
女性健康·同性之恋
电脑网络
网络编程·网页制作·软件教学
操作系统·图形图象·冲浪宝典
网络安全·邮件系统·认证考试
热点专题
芙蓉·真人漫画
72式·欲望都市
帅哥·人体彩绘
您现在的位置: 世纪中国 >> 网络编程 >> ASP.NET教学 >> asp.net技巧 >> 教程正文
ASP.NET 2.0中的输出缓存
作者:中国图霸    教程来源:网络    点击数:    更新时间:2007-1-1
. However, you do not have to understand design patterns in order to understand this article.

The example code shown in this article is written in C#, but the concepts are applicable to any .NET language.

What is the problem?
In this section of the article I will describe the problems with direct access to the HttpSessionState class, without the facade. I will describe the kinds of bugs that can be introduced.

The following shows the typical code written to access session-state variables.

// Save a session variable
Session["some string"] = anyOldObject;
// Read a session variable
DateTime startDate = (DateTime)Session["StartDate"];


The problems arise from the flexibile interface provided by HttpSessionState: the keys are just strings and the values are not strongly typed.

Using String Literals as Keys
If string literals are used as the keys, the string value of the key is not checked by the compiler. It is easy to create new session values by simple typing errors.

Session["received"] = 27;...
Session["recieved"] = 32;


In the code above, two separate session values have been saved.

Most bugs like this will be identified by unit testing – but not always. It may not always be apparent that the value has not changed as expected.

We can avoid this kind of bug by using constants:

private const string received = "received";...
Session[received] = 27;...
Session[received] = 32;


No Type Checking
There is no type checking of the values being stored in session variables. The compiler cannot check correctness of what is being stored.

Consider the following code:

Session["maxValue"] = 27;...
i

上一页  [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] 下一页

分类推荐
社会 社会 娱乐 军事 校园
幽默 体育 女性 专题
电脑 编程 网页 软件 系统
安全 图象 冲浪 认证
搞笑 人物 动物 物品 表情
签名 色图 漫画 奇闻
美女 明星 清纯 自拍 欧美
丝袜 卡通 性感 走光
两性 知识 性图 孕育 技巧
同性 单身 情感 实录
视频 写真 搞笑 MTV 翻唱
写实 片段 游戏 综艺
asp.net技巧热门文章
普通教程 ASP.NET里常用的JS
普通教程 UpdatePanel与UrlRewrite
普通教程 .net内存回收与Dispose﹐Close
普通教程 用MasterPage 代替 PageBase
普通教程 DataSet 添加数据集、行、列、
普通教程 ASP.NET组件DataGrid的分页实用
普通教程 使用WebClient自动填写并提交A
普通教程 ASP.NET中水晶报表的使用
普通教程 对NDoc支持.net2.0的异常分析及
普通教程 关于ASP.NET调用javascrip
普通教程 MSBuild, NAnt, NUnit, MSTest
普通教程 asp.net 2.0 上传控件的使用
普通教程 UpdatePanel和自定义控件中的客
普通教程 ASP.NET—From验证:全部代码及
普通教程 自己写的一个asp.net的生成曲线
普通教程 js操作listbox
普通教程 ASP.NET 崩溃-SiteMap中疯狂的
普通教程 ASP.NET 2.0-选用DataSet或Da
普通教程 用.net 处理xmlHttp发送异步请
普通教程 ASP.Net 2.0 图形控件简述

  广东广州海珠区 世纪网络工作室 版权所有 上海电信提供网络带宽
信箱: 9297659@qq.com 粤ICP备06113754号