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

推荐订阅源

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

博客园 - 小张.NET

模仿写了一个摸鱼应用解决原作者的问题 第一屏不显示懒加载的图片内容,这个方法可以搞定 C#多线程中访问winform控件 (解决Winform 对象当前正在其他地方使用) 变化的科技感十足的网站,推荐 新年有感 获取高精度时间注意事项 (QueryPerformanceCounter , QueryPerformanceFrequency) 修改 TeamViewer ID 的方法 VS2017离线安装包[百度云盘](收藏了) 老子今天不加班,程序员也需要自由 改变Eclipse 中代码字体大小 去除 VS.Net 2003 项目的 VSS 息的脚本 字符串截取固定长度的方法(C#) 对路径XXX的访问被拒绝(文件操作权限)的解决方法 安装VS2005 SP1之后无法更改或卸载VS2005的处理方法 VS2005的隐藏快捷键 vs2005的快捷键 反编译工具Reflector下载(集成两个常用.net插件,FileGenerator和FileDisassembler) 强大的.NET反编译工具Reflector及插件 程序员,你离坐牢还有多远 - 小张.NET - 博客园
两种彻底删除VIEWSTATE的方法 - 小张.NET - 博客园
小张.NET · 2007-11-19 · via 博客园 - 小张.NET

2007年08月28日 星期二 14:25

第一种方法:
         第一步,在Web.config文件的Pages配置节点中设置enableViewState="false",或者在每个Aspx页头部设置。完成第一步后,无论如何.Net也会在页面上输出<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="" />这样的内容。
         第二步,将<head runat="server">和<form id="form1" runat="server">中的runat="server"属性删除。完成第二步之后,asp.net默认不会再往客户端输出__VIEWSTATE元素。

第二种方法:
         第一步,同每一种方法中的第一步操作。
         第二步,重写Page类中的LoadPageStateFromPersistenceMedium()和SavePageStateToPersistenceMedium(object state)方法。

Demo:将ViewState存放到Session中:
protected LosFormatter losFormatter;

protected override object LoadPageStateFromPersistenceMedium()
{
      string key = Request.RawUrl + "__viewstate";

      if (Session[key] != null)
      {
          MemoryStream stream = (MemoryStream)Session[key];
          stream.Seek(0, SeekOrigin.Begin);
          return losFormatter.Deserialize(stream);
      }

      return null;
}

protected override void SavePageStateToPersistenceMedium(object state)
{
      string key = Request.RawUrl + "__viewstate";

      MemoryStream stream = new MemoryStream();

      losFormatter.Serialize(stream, state);

      stream.Flush();

      Session[key] = stream;
}