public virtual AntiForgeryData Deserialize(string serializedToken) { if (String.IsNullOrEmpty(serializedToken)) { throw new ArgumentException(MvcResources.Common_NullOrEmpty, "serializedToken"); } // call property getter outside try { } block so that exceptions bubble up for debugging IStateFormatter formatter = Formatter; try { Triplet deserializedObj = (Triplet)formatter.Deserialize(serializedToken); return(new AntiForgeryData() { Salt = (string)deserializedObj.First, Value = (string)deserializedObj.Second, CreationDate = (DateTime)deserializedObj.Third }); } catch (Exception ex) { throw CreateValidationException(ex); } }
public virtual string Serialize(object state, SerializationMode mode) { IStateFormatter formatter = GetFormatter(mode); string serializedValue = formatter.Serialize(state); return(serializedValue); }
void ILogger.Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter) { IStateFormatter <TState> stateFormatter = Options.StateFormatterFactory.Create <TState>(eventId, formatter); ProxiedEvent <TState> evt = new ProxiedEvent <TState>(logLevel, Options.Category, eventId.Name, state, stateFormatter); _loxy.Raise(evt); }
// // Persist any ViewState and ControlState. // public override void Save() { if (ViewState != null || ControlState != null) { if (Page.Session != null) { Stream stateStream = GetSecureStream(); StreamWriter writer = new StreamWriter(stateStream); IStateFormatter formatter = this.StateFormatter; Pair statePair = new Pair(ViewState, ControlState); // Serialize the statePair object to a string. string serializedState = formatter.Serialize(statePair); writer.Write(serializedState); writer.Close(); stateStream.Close(); } else { throw new InvalidOperationException("Session needed for StreamPageStatePersister."); } } }
public string Serialize() { IStateFormatter formatter = TokenPersister.CreateFormatter(); State state = new State(_value, _signature, _creationDate); return(formatter.Serialize(state)); }
/// <summary> /// Saves the Page State to the Cache /// </summary> /// <history> /// [cnurse] 11/30/2006 Documented /// </history> public override void Save() { //No processing needed if no states available if (ViewState == null & ControlState == null) { return; } if (Page.Session != null) { if (!(Directory.Exists(CacheDirectory))) { Directory.CreateDirectory(CacheDirectory); } // Write a state string, using the StateFormatter. StreamWriter writer = new StreamWriter(StateFileName, false); IStateFormatter formatter = this.StateFormatter; Pair statePair = new Pair(ViewState, ControlState); string serializedState = formatter.Serialize(statePair); writer.Write(serializedState); writer.Close(); } }
// // Summary: // Deserializes and loads persisted state from the repository when // a System.Web.UI.Page object initializes its control hierarchy. // // Exceptions: // T:System.Web.HttpException: // The System.Web.UI.SessionPageStatePersister.Load method could not successfully // deserialize the state contained in the request to the Web server. public override void Load() { string viewStateKey; if (UseDefaultViewStateHiddenField) { // Get key from __VIEWSTATE hidden field HiddenFieldPageStatePersister _hiddenFiledPagePersister = new HiddenFieldPageStatePersister(Page); _hiddenFiledPagePersister.Load(); viewStateKey = _hiddenFiledPagePersister.ViewState as string; } else { // Get key from custom hidden field //string viewStateKey = Page.Request.Params[ViewStateHiddenFieldName] as string; viewStateKey = Page.Request.Form[ViewStateHiddenFieldName] as string; } if (!string.IsNullOrEmpty(viewStateKey)) { ViewStateInfo info = (ViewStateInfo)Repository.GetViewState(viewStateKey); IStateFormatter formatter = this.StateFormatter; Pair statePair = (Pair)formatter.Deserialize((string)info.Value); ViewState = statePair.First; ControlState = statePair.Second; // Remove from repository after serve } }
/// ----------------------------------------------------------------------------- /// <summary> /// Loads the Page State from the Cache /// </summary> /// <history> /// [cnurse] 11/30/2006 Documented /// </history> /// ----------------------------------------------------------------------------- public override void Load() { StreamReader reader = null; //Read the state string, using the StateFormatter. try { reader = new StreamReader(StateFileName); string serializedStatePair = reader.ReadToEnd(); IStateFormatter formatter = StateFormatter; //Deserialize returns the Pair object that is serialized in //the Save method. var statePair = (Pair)formatter.Deserialize(serializedStatePair); ViewState = statePair.First; ControlState = statePair.Second; } finally { if (reader != null) { reader.Close(); } } }
public override void Load() { #if TARGET_J2EE if (Page.FacesContext != null) { if (Page.PageState != null) { ViewState = Page.PageState.First; ControlState = Page.PageState.Second; } return; } #endif string rawViewState = Page.RawViewState; IStateFormatter formatter = StateFormatter; if (!String.IsNullOrEmpty(rawViewState)) { Pair pair = formatter.Deserialize(rawViewState) as Pair; if (pair != null) { ViewState = pair.First; ControlState = pair.Second; } } }
public virtual CustomAntiForgeryData Deserialize(string serializedToken) { if (string.IsNullOrEmpty(serializedToken)) { throw new ArgumentException(CustomAntiForgeryResources.Common_NullOrEmpty, "serializedToken"); } IStateFormatter formatter = this.Formatter; CustomAntiForgeryData result; try { object[] array = (object[])formatter.Deserialize(serializedToken); result = new CustomAntiForgeryData { Salt = (string)array[0], Value = (string)array[1], CreationDate = (DateTime)array[2], Username = (string)array[3] }; } catch (Exception innerException) { if (CustomAntiForgeryConfig.DebugMode) { CM.Web.AntiForgery.Custom.Logger.Exception(CustomAntiForgeryDataSerializer_.CreateValidationException(innerException)); result = null; } else { throw CustomAntiForgeryDataSerializer_.CreateValidationException(innerException); } } return(result); }
/// <summary> /// Loads the view and control states. /// </summary> /// <param name="viewStateId">The identifier of the state.</param> /// <param name="stateFormatter">An instance of System.Web.UI.IStateFormatter that is used to serialize and deserialize object state.</param> /// <returns>The object that stores the view and control states.</returns> public static Pair GetViewState(Guid viewStateId, IStateFormatter stateFormatter) { if (stateFormatter == null) { return(null); } if (viewStateId == Guid.Empty) { return(null); } using (SqlConnection connection = new SqlConnection(FrameworkConfiguration.Current.WebApplication.ViewState.ConnectionString)) { using (SqlCommand command = new SqlCommand("[dbo].[Mc_GetViewState]", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.Add("@ViewStateId", SqlDbType.UniqueIdentifier).Value = viewStateId; connection.Open(); using (SqlDataReader reader = command.ExecuteReader()) { Pair statePair = null; MemoryStream stream = null; StreamReader sr = null; try { if (reader.Read()) { stream = new MemoryStream(reader[0] as byte[]); } if (stream != null) { sr = new StreamReader(stream); statePair = (stateFormatter.Deserialize(sr.ReadToEnd()) as Pair); } return(statePair); } finally { if (sr != null) { sr.Dispose(); } else if (stream != null) { stream.Dispose(); } } } } } }
internal void RestoreEventValidationState(string fieldValue) { if (!page.EnableEventValidation || fieldValue == null || fieldValue.Length == 0) { return; } IStateFormatter fmt = page.GetFormatter(); eventValidationValues = (int [])fmt.Deserialize(fieldValue); eventValidationPos = eventValidationValues.Length; }
public ProxiedEvent(LogLevel level, string category, string message, TState state, IStateFormatter <TState> customStateFormatter) : base(level, category, message, state) { if (customStateFormatter == null) { throw new ArgumentNullException("customStateFormatter"); } _stateFormatter = customStateFormatter; }
private object DeSerializeInternal(IStateFormatter StateFormatter, byte[] bytes) { ObjectStateFormatter format = (ObjectStateFormatter)StateFormatter; MemoryStream memoryStream = (MemoryStream)_GetMemoryStream.Invoke(format, null); memoryStream.Write(bytes, 0, bytes.Length); memoryStream.Position = 0; object viewState = format.Deserialize(memoryStream); memoryStream.Position = 0; memoryStream.SetLength(0); return(viewState); }
private byte[] SerializeInternal(IStateFormatter StateFormatter, object viewState) { ObjectStateFormatter format = (ObjectStateFormatter)StateFormatter; MemoryStream memoryStream = (MemoryStream)_GetMemoryStream.Invoke(format, null); format.Serialize(memoryStream, viewState); memoryStream.SetLength(memoryStream.Position); byte[] bytes = new byte[memoryStream.Length]; Array.Copy(memoryStream.GetBuffer(), bytes, memoryStream.Length); memoryStream.Position = 0; memoryStream.SetLength(0); return(bytes); }
public virtual object Deserialize(string value, SerializationMode mode) { Precondition.Defined(value, () => Error.ArgumentNull("value")); IStateFormatter formatter = GetFormatter(mode); try { return(formatter.Deserialize(value)); } catch (Exception ex) { throw Error.CouldNotDeserializeModelState(ex); } }
public override void Load() { string rawViewState = Page.RawViewState; IStateFormatter formatter = StateFormatter; if (!String.IsNullOrEmpty(rawViewState)) { Pair pair = formatter.Deserialize(rawViewState) as Pair; if (pair != null) { ViewState = pair.First; ControlState = pair.Second; } } }
public override void Save() { #if TARGET_J2EE if (Page.FacesContext != null) { if (ViewState != null || ControlState != null) { Page.PageState = new Pair(ViewState, ControlState); } return; } #endif IStateFormatter formatter = StateFormatter; Page.RawViewState = formatter.Serialize(new Pair(ViewState, ControlState)); }
public virtual object Deserialize(string serializedValue, SerializationMode mode) { if (String.IsNullOrEmpty(serializedValue)) { throw new ArgumentException(MvcResources.Common_NullOrEmpty, "serializedValue"); } IStateFormatter formatter = GetFormatter(mode); try { object deserializedValue = formatter.Deserialize(serializedValue); return(deserializedValue); } catch (Exception ex) { throw CreateSerializationException(ex); } }
internal string GetEventValidationStateFormatted() { if (eventValidationValues == null || eventValidationValues.Length == 0) { return(null); } if (page.IsCallback && !_hasRegisteredForEventValidationOnCallback) { return(null); } IStateFormatter fmt = page.GetFormatter(); int [] array = new int [eventValidationPos]; Array.Copy(eventValidationValues, array, eventValidationPos); return(fmt.Serialize(array)); }
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; } } } } }
// // Load ViewState and ControlState. // public override void Load() { Stream stateStream = GetSecureStream(); // Read the state string, using the StateFormatter. StreamReader reader = new StreamReader(stateStream); IStateFormatter formatter = this.StateFormatter; string fileContents = reader.ReadToEnd(); // Deserilize returns the Pair object that is serialized in // the Save method. Pair statePair = (Pair)formatter.Deserialize(fileContents); ViewState = statePair.First; ControlState = statePair.Second; reader.Close(); stateStream.Close(); }
public static RequestValidationToken Create(string serializedTokenData) { RequestValidationToken token = new RequestValidationToken(); IStateFormatter formatter = TokenPersister.CreateFormatter(); try { State state = (State)formatter.Deserialize(serializedTokenData); token._value = state.Value; token._signature = state.Signature; token._creationDate = state.CreationDate; } catch (Exception exception) { throw Error.RequestValidationError(exception); } return(token); }
public override void Save() { if (ViewState == null && ControlState == null) { return; } if (Page.Session != null) { if (!Directory.Exists(CacheDirectory)) { Directory.CreateDirectory(CacheDirectory); } StreamWriter writer = new StreamWriter(StateFileName, false); IStateFormatter formatter = this.StateFormatter; Pair statePair = new Pair(ViewState, ControlState); string serializedState = formatter.Serialize(statePair); writer.Write(serializedState); writer.Close(); } }
public override void Load() { StreamReader reader = null; try { reader = new StreamReader(StateFileName); string serializedStatePair = reader.ReadToEnd(); IStateFormatter formatter = this.StateFormatter; Pair statePair = (Pair)formatter.Deserialize(serializedStatePair); ViewState = statePair.First; ControlState = statePair.Second; } finally { if (reader != null) { reader.Close(); } } }
/// ----------------------------------------------------------------------------------------------------------------------------------------------------------------- /// <summary> /// Load the view state from persistent medium. /// </summary> /// <remarks> /// <author>jhill</author> /// <creation>Wednesday, 30 May 2007</creation> /// </remarks> /// ----------------------------------------------------------------------------------------------------------------------------------------------------------------- public override void Load() { // Load view state from DB string pageViewState = PageViewStateServices.GetByID(GetViewStateID()); if (pageViewState == null) { ViewState = null; ControlState = null; } else { // Deserialize into a Pair of ViewState and ControlState objects IStateFormatter formatter = StateFormatter; Pair statePair = (Pair)formatter.Deserialize(pageViewState); // Update ViewState and ControlState ViewState = statePair.First; ControlState = statePair.Second; } }
/// <summary> /// Stores the view and control states. /// </summary> /// <param name="viewStateId">The identifier of the state.</param> /// <param name="stateFormatter">An instance of System.Web.UI.IStateFormatter that is used to serialize and deserialize object state.</param> /// <param name="statePair">The object that stores the view and control states.</param> public static void InsertViewState(Guid viewStateId, IStateFormatter stateFormatter, Pair statePair) { if (stateFormatter == null) { return; } byte[] bytes = Support.GetBytes(stateFormatter.Serialize(statePair)); using (SqlConnection connection = new SqlConnection(FrameworkConfiguration.Current.WebApplication.ViewState.ConnectionString)) { using (SqlCommand command = new SqlCommand("[dbo].[Mc_InsertViewState]", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.Add("@ViewStateId", SqlDbType.UniqueIdentifier).Value = viewStateId; command.Parameters.Add("@ViewState", SqlDbType.VarBinary).Value = bytes; command.Parameters.Add("@ExpirationTime", SqlDbType.DateTime).Value = DateTime.UtcNow.AddMinutes(FrameworkConfiguration.Current.WebApplication.ViewState.ExpirationTimeout); connection.Open(); command.ExecuteNonQuery(); } } }
/// ----------------------------------------------------------------------------------------------------------------------------------------------------------------- /// <summary> /// Save the view state to persistent medium. /// </summary> /// <remarks> /// <author>jhill</author> /// <creation>Wednesday, 30 May 2007</creation> /// </remarks> /// <param name="viewState">View state to save.</param> /// ----------------------------------------------------------------------------------------------------------------------------------------------------------------- public override void Save() { // Create a pair for ViewState and ControlState Pair statePair = new Pair(ViewState, ControlState); IStateFormatter formatter = StateFormatter; // Save the view state Guid id = GetViewStateID(); PageViewStateServices.Save(id, formatter.Serialize(statePair)); // Store the ID of the view state in a hidden form field HtmlInputHidden control = _page.FindControl("__VIEWSTATEID") as HtmlInputHidden; if (control == null) { ScriptManager.RegisterHiddenField(_page, "__VIEWSTATEID", id.ToString()); } else { control.Value = id.ToString(); } }
// // Summary: // Serializes any object state contained in the System.Web.UI.PageStatePersister.ViewState // or the System.Web.UI.PageStatePersister.ControlState property and writes the // state to the repository. public override void Save() { if (base.ViewState == null && base.ControlState == null) { return; } IStateFormatter formatter = this.StateFormatter; Pair statePair = new Pair(ViewState, ControlState); // Serialize the statePair object to a string. string serializedState = formatter.Serialize(statePair); ViewStateInfo info = new ViewStateInfo(serializedState); string viewStateKey = Page.Request.Form[ViewStateHiddenFieldName] as string; if (!string.IsNullOrEmpty(viewStateKey)) { info.Id = viewStateKey; } Repository.SaveViewState(info); if (UseDefaultViewStateHiddenField) { // Save key in __VIEWSTATE hidden field HiddenFieldPageStatePersister _hiddenFiledPagePersister = new HiddenFieldPageStatePersister(Page); _hiddenFiledPagePersister.ViewState = info.Id; _hiddenFiledPagePersister.Save(); } else { // Register hidden field to store cache key in Page.ClientScript.RegisterHiddenField(ViewStateHiddenFieldName, info.Id); } }
internal GridView(IStateFormatter stateFormatter) { this._pageCount = -1; this._editIndex = -1; this._selectedIndex = -1; this._sortExpression = string.Empty; this._stateFormatter = stateFormatter; }
internal static string SerializeWithAssert(IStateFormatter formatter, object stateGraph) { return formatter.Serialize(stateGraph); }
private byte[] GetMacKeyModifier(IStateFormatter StateFormatter) { return((byte[])_GetMacKeyModifier.Invoke(StateFormatter, null)); }
internal static object DeserializeWithAssert(IStateFormatter formatter, string serializedState) { return formatter.Deserialize(serializedState); }