Esempio n. 1
0
        public override void Load()
        {
            _hiddenFiledPagePersister.Load();

            string viewStateStr = _hiddenFiledPagePersister.ViewState as string; // Page.Request.Form[STATE_KEY];

            trace.WriteTrace(TraceSeverity.InformationEvent, TraceCategory.Content, "View state: " + viewStateStr);

            if (viewStateStr != null && viewStateStr.StartsWith(CacheKeyPrefix)) // state not inline check the cached state key
            {
                string state = LoadState(viewStateStr);
                if (state == null)
                {
                    trace.WriteTrace(TraceSeverity.CriticalEvent, TraceCategory.Content, "View state lost. Probably cached item expired.");
                }
                else
                {
                    try
                    {
                        Pair data = (Pair)StateFormatter.Deserialize(state);
                        ViewState    = data.First;
                        ControlState = data.Second;
                    }
                    catch
                    {
                        trace.WriteTrace(TraceSeverity.Exception, TraceCategory.Content, String.Format("Could not deserialize view state. View state is invalid."));
                    }
                }
            }
            else
            {
                ViewState    = _hiddenFiledPagePersister.ViewState;
                ControlState = _hiddenFiledPagePersister.ControlState;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Десериализация ViewState
        /// </summary>
        /// <param name="serializedViewState"></param>
        protected void Deserialize(string serializedViewState)
        {
            object vsPair = StateFormatter.Deserialize(serializedViewState);

            if (vsPair != null && (vsPair is Pair))
            {
                var myPair = vsPair as Pair;
                ViewState    = myPair.First;
                ControlState = myPair.Second;
            }
            else
            {
                ViewState = vsPair;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 加载ViewState。如果ViewState的尺寸小于配置信息中的值(缺省为10K),从隐藏域中加载,否则从数据库中加载
        /// </summary>
        public override void Load()
        {
            string data = this.Page.Request.Form["__VIEWSTATE"];

            if (string.IsNullOrEmpty(data) == false)
            {
                #region 注释掉原有的逻辑
                //Pair statePair = (Pair)StateFormatter.Deserialize(data);
                //ControlState = statePair.Second;
                //ViewState = statePair.First;
                #endregion

                long id;
                if (long.TryParse(ViewState.ToString(), out id))
                {
                    string stateStr = LoadStateFromDB(id);
                    ViewState = StateFormatter.Deserialize(stateStr);
                }
            }
        }
Esempio n. 4
0
        protected override Object LoadPageStateFromPersistenceMedium()
        {
            Object state = null;

            String clientViewStateString = _requestValueCollection[ViewStateID];

            if (clientViewStateString != null)
            {
                _privateViewState =
                    StateFormatter.Deserialize(clientViewStateString) as Hashtable;
                if (_privateViewState != null)
                {
                    String[] arr = _privateViewState[PageClientViewStateKey] as String[];
                    if (arr != null)
                    {
                        _activeFormID = arr[0];

                        String id = arr[1];
                        if (id != null)
                        {
                            _sessionViewState.Load(this, id);
                            state = _sessionViewState.ViewState;
                            if (state == null)
                            {
                                OnViewStateExpire(EventArgs.Empty);
                            }
                            else
                            {
                                Object[] arrState = state as Object[];
                                if (arrState != null)
                                {
                                    _privateViewState = (Hashtable)arrState[1];
                                    state             = arrState[0];
                                }
                            }
                        }
                    }
                    _privateViewState.Remove(PageClientViewStateKey);

                    // If the page had no view state, but had controls requiring postback,
                    // this information was saved in client view state.

                    Object controlsRequiringPostBack =
                        _privateViewState[_controlsRequiringPostBackKey];
                    if (controlsRequiringPostBack != null)
                    {
                        state = new Triplet(GetTypeHashCode().ToString(),
                                            null,
                                            controlsRequiringPostBack);
                        _privateViewState.Remove(_controlsRequiringPostBackKey);
                    }

                    // Apply whatever private view state can be applied now.

                    foreach (DictionaryEntry entry in _privateViewState)
                    {
                        if (entry.Value != null)
                        {
                            MobileControl ctl = FindControl((String)entry.Key) as MobileControl;
                            if (ctl != null)
                            {
                                ctl.LoadPrivateViewStateInternal(entry.Value);
                            }
                        }
                    }
                }
            }

            _privateViewStateLoaded = true;

            if (state == null)
            {
                // Give framework back an empty page view state
                state = new Triplet(GetTypeHashCode().ToString(), null, null);
            }
            return(state);
        }