asp.net 去掉viewstate
解决办法:app_code/ 存放一个类 用来截获HTTP
1.代码如下
using System;
using System.IO;
using System.Web;
using System.Text;
using System.Text.RegularExpressions;
/// <summary>
/// Removes whitespace from the webpage.
/// </summary>
public class ViewstateModule : IHttpModule
{
#region IHttpModule Members
void IHttpModule.Dispose()
{
// Nothing to dispose;
}
void IHttpModule.Init(HttpApplication context)
{
context.BeginRequest += new EventHandler(context_BeginRequest);
}
#endregion
void context_BeginRequest(object sender, EventArgs e)
{
HttpApplication app = sender as HttpApplication;
//if (app.Request.Url.OriginalString.Contains(".aspx"))
//{
// app.Response.Filter = new ViewstateFilter(app.Response.Filter);
//}
//reg/目录下的不进行优化 因为发现render 后,验证码不能显示
if (!app.Request.Url.OriginalString.Contains("/reg/"))
{
if (app.Request.Url.OriginalString.Contains(".aspx"))
{
app.Response.Filter = new ViewstateFilter(app.Response.Filter);
}
}
//静态化后重也要处理
if (app.Request.Url.OriginalString.Contains(".html"))
{
app.Response.Filter = new ViewstateFilter(app.Response.Filter);
}
}
#region Stream filter
private class ViewstateFilter : Stream
{
public ViewstateFilter(Stream sink)
{
_sink = sink;
}
private Stream _sink;
#region Properites
public override bool CanRead
{
get { return true; }
}
public override bool CanSeek
{
get { return true; }
}
public override bool CanWrite
{
get { return true; }
}
public override void Flush()
{
_sink.Flush();
}
相关文档:
作者: Stephen Walther
原文地址:http://msdn.microsoft.com/asp.net/default.aspx?pull=/library/en-us/dnvs05/html/UserProfiles.asp
译
者:Tony Qu
概要:许多ASP.NET应用程序需要跨访问的用户属性
跟踪功能,在ASP.NET1.1中,我们只能人工实现这一功能。但如今,使用 ASP.NET 2.0的Profile对象,这个过程变得异
......
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Xml;
namespace jiu ......
//详细介绍asp.net获取日期时间的各种格式的函数
DateTime.Now.ToLocalTime().ToString(); // 2009-9-5 20:12:12
//获取日期
DateTime.Now.ToLongDateString().ToString(); // 2009年9月5日
......
1、使用值类型的ToString方法
在连接字符串时,经常使用"+"号直接将数字添加到字符串中。这种方法虽然简单,也可以得到正确结果,但是由于涉及到不同的数据类型,数字需要通过装箱操作转化为引用类型才可以添加到字符串中。但是装箱操作对性能影响较大,因为在进行这类处理时,将在托管堆中分配一个新的对象,原有的值 ......
有很多理由去解释理解ASP.NET页面生命周期是非常重要的,主要是要去理解什么地方放置什么特定的方法,什么时候我们应该设置什么相关的属性。如果去开发自定义的服务器控件,理解生命周期对纠正控件初始化时候的错误,以及使用view-state和后台代码设置属性是非常有用的。(控件事件只与ASP.NET页面相关)
&nb ......