public override void Load()
        {
            NameValueCollection requestValueCollection = Page.RequestValueCollection;

            if (requestValueCollection == null)
            {
                return;
            }

            string viewStateString = null;

            try {
                viewStateString = Page.RequestViewStateString;

                // VSWhidbey 160556
                if (!String.IsNullOrEmpty(viewStateString) || !String.IsNullOrEmpty(Page.ViewStateUserKey))
                {
                    Pair combinedState = (Pair)Util.DeserializeWithAssert(StateFormatter2, viewStateString, Purpose.WebForms_HiddenFieldPageStatePersister_ClientState);
                    ViewState    = combinedState.First;
                    ControlState = combinedState.Second;
                }
            }
            catch (Exception e) {
                // throw if this is a wrapped ViewStateException -- mac validation failed
                if (e.InnerException is ViewStateException)
                {
                    throw;
                }

                ViewStateException.ThrowViewStateError(e, viewStateString);
            }
        }
 public override void Load()
 {
     if (base.Page.RequestValueCollection != null)
     {
         string requestViewStateString = null;
         try
         {
             requestViewStateString = base.Page.RequestViewStateString;
             if (!string.IsNullOrEmpty(requestViewStateString) || !string.IsNullOrEmpty(base.Page.ViewStateUserKey))
             {
                 Pair pair = (Pair)Util.DeserializeWithAssert(base.StateFormatter, requestViewStateString);
                 base.ViewState    = pair.First;
                 base.ControlState = pair.Second;
             }
         }
         catch (Exception exception)
         {
             if (exception.InnerException is ViewStateException)
             {
                 throw;
             }
             ViewStateException.ThrowViewStateError(exception, requestViewStateString);
         }
     }
 }
 private static string GetCorrectErrorPageMessage(ViewStateException vse, string message)
 {
     if (!vse.IsConnected)
     {
         return System.Web.SR.GetString("ViewState_ClientDisconnected");
     }
     return System.Web.SR.GetString(message);
 }
 private static string GetCorrectErrorPageMessage(ViewStateException vse, string message)
 {
     if (!vse.IsConnected)
     {
         return(System.Web.SR.GetString("ViewState_ClientDisconnected"));
     }
     return(System.Web.SR.GetString(message));
 }
Example #5
0
        /// <devdoc>
        ///    <para>Deserializes a LOS formatted object from a string.</para>
        /// </devdoc>
        public object Deserialize(string input)
        {
#if NO_BASE64
            char[] data = input.ToCharArray();
#else
            byte[] dataBytes = Convert.FromBase64String(input);

            int dataLength = -1;
            if (EnableViewStateMac)
            {
                try {
                    dataBytes = MachineKeySection.GetDecodedData(dataBytes, _macKey, 0, dataBytes.Length, ref dataLength);
                }
                catch (Exception e) {
                    PerfCounters.IncrementCounter(AppPerfCounter.VIEWSTATE_MAC_FAIL);
                    ViewStateException.ThrowMacValidationError(e, input);
                }
            }

            if (dataLength == -1)
            {
                dataLength = dataBytes.Length;
            }

            char[] data = EncodingInstance.GetChars(dataBytes, 0, dataLength);
#endif


            // clear or allocate name and type tables.
            //
            if (_deserializedTypeTable == null)
            {
                _deserializedTypeTable      = new ArrayList();
                _deserializedConverterTable = new ListDictionary();
            }
            else
            {
                _deserializedTypeTable.Clear();
                _deserializedConverterTable.Clear();
            }

            _builder    = (char[])_charBufferAllocator.GetBuffer();
            _recyclable = true;

            // DeserializeValueInternal is recursive, so we just kick this off
            // starting at 0
            _current             = 0;
            _deserializationData = data;
            object ret = DeserializeValueInternal();

            if (_recyclable)
            {
                _charBufferAllocator.ReuseBuffer(_builder);
            }

            return(ret);
        }
        private static void ThrowError(Exception inner, string persistedState, string errorPageMessage, bool macValidationError)
        {
            ViewStateException innerException = new ViewStateException(inner, persistedState)
            {
                _macValidationError = macValidationError
            };
            HttpException e = new HttpException(GetCorrectErrorPageMessage(innerException, errorPageMessage), innerException);

            e.SetFormatter(new UseLastUnhandledErrorFormatter(e));
            throw e;
        }
Example #7
0
 // if the client disconnected, we want to display that at the top of the error page
 private static string GetCorrectErrorPageMessage(ViewStateException vse, string message)
 {
     if (!vse.IsConnected)
     {
         return(SR.GetString(SR.ViewState_ClientDisconnected));
     }
     else
     {
         return(SR.GetString(message));
     }
 }
Example #8
0
        // Returns true if this exception was caused by a view state MAC validation failure; false otherwise
        internal static bool IsMacValidationException(Exception e)
        {
            for (; e != null; e = e.InnerException)
            {
                ViewStateException vse = e as ViewStateException;
                if (vse != null && vse._macValidationError)
                {
                    return(true);
                }
            }

            // not a ViewState MAC validation exception
            return(false);
        }
Example #9
0
        private static void ThrowError(Exception inner, string persistedState, string errorPageMessage,
                                       bool macValidationError)
        {
            ViewStateException middle;
            HttpException      outer;

            middle = new ViewStateException(inner, persistedState);
            middle._macValidationError = macValidationError;

            // Setup the formatter for this exception, to make sure this message shows up
            // in an error page as opposed to the inner-most exception's message.
            outer = new HttpException(GetCorrectErrorPageMessage(middle, errorPageMessage), middle);
            outer.SetFormatter(new UseLastUnhandledErrorFormatter(outer));

            throw outer;
        }
Example #10
0
 private void EnsureEventValidationFieldLoaded()
 {
     if (!this._eventValidationFieldLoaded)
     {
         this._eventValidationFieldLoaded = true;
         string str = null;
         if (this._owner.RequestValueCollection != null)
         {
             str = this._owner.RequestValueCollection["__EVENTVALIDATION"];
         }
         if (!string.IsNullOrEmpty(str))
         {
             IStateFormatter formatter = this._owner.CreateStateFormatter();
             ArrayList       list      = null;
             try
             {
                 list = formatter.Deserialize(str) as ArrayList;
             }
             catch (Exception exception)
             {
                 ViewStateException.ThrowViewStateError(exception, str);
             }
             if ((list != null) && (list.Count >= 1))
             {
                 int    num = (int)list[0];
                 string requestViewStateString = this._owner.RequestViewStateString;
                 if (num != StringUtil.GetStringHashCode(requestViewStateString))
                 {
                     ViewStateException.ThrowViewStateError(null, str);
                 }
                 this._clientPostBackValidatedEventTable = new HybridDictionary(list.Count - 1, true);
                 for (int i = 1; i < list.Count; i++)
                 {
                     int num3 = (int)list[i];
                     this._clientPostBackValidatedEventTable[num3] = null;
                 }
                 if (this._owner.IsCallback)
                 {
                     this._validEventReferences = list;
                 }
             }
         }
     }
 }
Example #11
0
        public object Deserialize(string inputString)
        {
            if (string.IsNullOrEmpty(inputString))
            {
                throw new ArgumentNullException("inputString");
            }
            byte[] buf    = Convert.FromBase64String(inputString);
            int    length = buf.Length;

            try
            {
                if ((this._page != null) && this._page.ContainsEncryptedViewState)
                {
                    buf    = MachineKeySection.EncryptOrDecryptData(false, buf, this.GetMacKeyModifier(), 0, length);
                    length = buf.Length;
                }
                else if (((this._page != null) && this._page.EnableViewStateMac) || (this._macKeyBytes != null))
                {
                    buf = MachineKeySection.GetDecodedData(buf, this.GetMacKeyModifier(), 0, length, ref length);
                }
            }
            catch
            {
                PerfCounters.IncrementCounter(AppPerfCounter.VIEWSTATE_MAC_FAIL);
                ViewStateException.ThrowMacValidationError(null, inputString);
            }
            object       obj2         = null;
            MemoryStream memoryStream = GetMemoryStream();

            try
            {
                memoryStream.Write(buf, 0, length);
                memoryStream.Position = 0L;
                obj2 = this.Deserialize(memoryStream);
            }
            finally
            {
                ReleaseMemoryStream(memoryStream);
            }
            return(obj2);
        }
 // if the client disconnected, we want to display that at the top of the error page
 private static string GetCorrectErrorPageMessage(ViewStateException vse, string message) {
     if (!vse.IsConnected)
         return SR.GetString(SR.ViewState_ClientDisconnected);
     else
         return SR.GetString(message);
 }
Example #13
0
 internal protected WebViewStateFailureAuditEvent(string message, object eventSource, int eventCode, int eventDetailCode, ViewStateException viewStateException)
     :base(message, eventSource, eventCode, eventDetailCode)
 {
     _viewStateException = viewStateException;
 }
 protected internal WebViewStateFailureAuditEvent(string message, object eventSource, int eventCode, int eventDetailCode, System.Web.UI.ViewStateException viewStateException) : base(message, eventSource, eventCode, eventDetailCode)
 {
     this._viewStateException = viewStateException;
 }
 protected internal WebViewStateFailureAuditEvent(string message, object eventSource, int eventCode, int eventDetailCode, System.Web.UI.ViewStateException viewStateException) : base(message, eventSource, eventCode, eventDetailCode)
 {
     this._viewStateException = viewStateException;
 }
 private static void ThrowError(Exception inner, string persistedState, string errorPageMessage, bool macValidationError)
 {
     ViewStateException innerException = new ViewStateException(inner, persistedState) {
         _macValidationError = macValidationError
     };
     HttpException e = new HttpException(GetCorrectErrorPageMessage(innerException, errorPageMessage), innerException);
     e.SetFormatter(new UseLastUnhandledErrorFormatter(e));
     throw e;
 }
        private static void ThrowError(Exception inner, string persistedState, string errorPageMessage,
                                        bool macValidationError) {
            ViewStateException middle;
            HttpException outer;

            middle = new ViewStateException(inner, persistedState);  
            middle._macValidationError = macValidationError;

            // Setup the formatter for this exception, to make sure this message shows up
            // in an error page as opposed to the inner-most exception's message.
            outer = new HttpException(GetCorrectErrorPageMessage(middle, errorPageMessage), middle);
            outer.SetFormatter(new UseLastUnhandledErrorFormatter(outer));

            throw outer;
        }
 private void AddViewStateExceptionDataFields(ArrayList dataFields, ViewStateException vse)
 {
     dataFields.Add(System.Web.SR.GetString(vse.ShortMessage));
     dataFields.Add(vse.RemoteAddress);
     dataFields.Add(vse.RemotePort);
     dataFields.Add(vse.UserAgent);
     dataFields.Add(vse.PersistedState);
     dataFields.Add(vse.Referer);
     dataFields.Add(vse.Path);
 }