示例#1
0
        protected override object LoadPageStateFromPersistenceMedium()
        {
            #region
            byte[] obytes = new byte[] { };

            switch (VS_SaveMethod)
            {
            case ViewStateSaveMethod.Page:
            {
                string zipvstate     = this.Page.Request.Form.Get("__Benny_P");
                string usezip_vstate = this.Page.Request.Form.Get("__Benny_PZ");
                if (Equals(usezip_vstate, "true"))
                {
                    obytes = DeCompress(zipvstate);
                }
                else
                {
                    obytes = System.Convert.FromBase64String(zipvstate);
                }
            }
            break;

            case ViewStateSaveMethod.Cache:
            {
                string key = this.Page.Request.Form.Get("__Benny_C");
                try
                {
                    obytes = System.Convert.FromBase64String(MyCache <string> .Get(key));
                }
                catch { obytes = new byte[] { }; }
            }
            break;

            case ViewStateSaveMethod.Session:
            {
                string key = this.Page.Request.Form.Get("__Benny_S");
                try
                {
                    obytes = System.Convert.FromBase64String(Session[key].ToString());
                }
                catch { obytes = new byte[] { }; }
            }
            break;
            }
            LosFormatter lformat = new LosFormatter();
            return(lformat.Deserialize(System.Convert.ToBase64String(obytes)));

            #endregion
        }
示例#2
0
        protected override void SavePageStateToPersistenceMedium(object viewState)
        {
            #region
            System.IO.StringWriter sw      = new StringWriter();
            LosFormatter           lformat = new LosFormatter();
            lformat.Serialize(sw, viewState);

            string vString = sw.ToString();

            bool userzip = false;

            switch (VS_SaveMethod)
            {
            case ViewStateSaveMethod.Page:
            {
                if (vString.Length > limiteLength)
                {
                    userzip = true;
                    byte[] mbytes = Compress(vString);
                    vString = System.Convert.ToBase64String(mbytes);
                }
                this.Page.ClientScript.RegisterHiddenField("__Benny_P", vString);
                this.Page.ClientScript.RegisterHiddenField("__Benny_PZ", userzip.ToString().ToLower());
            }
            break;

            case ViewStateSaveMethod.Cache:
            {
                string key = Guid.NewGuid().ToString().Replace("-", "");
                MyCache <string> .Insert(key, vString, HttpContext.Current.Session.Timeout * 60);

                this.Page.ClientScript.RegisterHiddenField("__Benny_C", key);
            }
            break;

            case ViewStateSaveMethod.Session:
            {
                string key = Guid.NewGuid().ToString().Replace("-", "");
                HttpContext.Current.Session[key] = vString;
                this.Page.ClientScript.RegisterHiddenField("__Benny_S", key);
            }
            break;
            }

            #endregion
        }