DNN Remove ViewState

4053 단어 remove
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
 
참조:
http://blogs.msdn.com/b/alikl/archive/2008/01/08/how-to-keep-asp-net-viewstate-on-the-server-revised.aspx
http://blogs.msdn.com/b/alikl/archive/2008/01/02/basic-sample-how-to-keep-asp-net-viewstate-on-the-server.aspx
SessionPageStatePersister - 
http://msdn.microsoft.com/en-us/library/system.web.ui.sessionpagestatepersister.sessionpagestatepersister(v=VS.90).aspx
 
 
2003년 발표:
http://aspalliance.com/72
 
국내:
http://www.cnblogs.com/xuhengzhang/archive/2004/12/30/84159.html
http://www.cnblogs.com/xiaozhang/archive/2007/11/19/964291.html

좋은 웹페이지 즐겨찾기