asp.net 隐藏页面<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value=''>的值

 protected LosFormatter losFormatter = new LosFormatter();

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

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

        return null;
    }

    protected override void SavePageStateToPersistenceMedium(object viewState)
    {
        string key = Request.RawUrl + "__viewstate";
        System.IO.MemoryStream stream = new System.IO.MemoryStream();
        losFormatter.Serialize(stream, viewState);
        stream.Flush();
        Session[key] = stream;
    }
posted @ 2012-05-31 12:57  事理  阅读(2958)  评论(1编辑  收藏  举报