DNN Remove ViewState

VB.net:
Protected Overrides Function LoadPageStateFromPersistenceMedium() As Object
            Dim key As String = Request.RawUrl + "__viewstate"
            If Session(key) IsNot Nothing Then
                Dim stream As MemoryStream = DirectCast(Session(key), MemoryStream)
                stream.Seek(0, SeekOrigin.Begin)
                Return losFormatter.Deserialize(stream)
            End If
            Return Nothing
        End Function
        Protected Overrides Sub SavePageStateToPersistenceMedium(ByVal state As Object)
            Dim key As String = Request.RawUrl + "__viewstate"
            Dim stream As New MemoryStream()
            losFormatter.Serialize(stream, state)
            stream.Flush()
            Session(key) = stream
        End Sub

 

C#:

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;
        }

 

里面涉及到一个参数的定义:

protected LosFormatter losFormatter = new LosFormatter();

 

另外Cache方式:

protected override void SavePageStateToPersistenceMedium(object viewState)
{
string str = "VIEWSTATE_" + Request.UserHostAddress + "_" + DateTime.Now.Ticks.ToString();
Cache.Add(str, viewState, null, DateTime.Now.AddMinutes(Session.Timeout),TimeSpan.Zero, CacheItemPriority.Default, null);
RegisterHiddenField("__VIEWSTATE_KEY", str);
RegisterHiddenField("__VIEWSTATE", "");
}

protected override object LoadPageStateFromPersistenceMedium()
{
string str = Request.Form["__VIEWSTATE_KEY"];
if (!str.StartsWith("VIEWSTATE_")) {
throw new Exception("Invalid viewstate key:" + str);
}
return Cache[str];
}

 

参见:http://www.eggheadcafe.com/articles/20040613.asp

 

参考:
 
 
2003年发布的:http://aspalliance.com/72
 
posted @ 2011-07-04 11:48  无尽思绪  阅读(271)  评论(0编辑  收藏  举报