Asp.net Invalid character in Base-64 string

I have a C # mobile site and I have a problem with some mobile clients. I placed the trace below, but basically the browser of the phone or wap-gateway that the phone connects to the Internet url encodes the hidden input in the form of a view.

/ wEPDwULLTExNTMyOTcwOTBkGAEFBlBtTGlzdA9nZA ==

becomes

% 2FwEPDwULLTExNTMyOTcwOTBkGAEFBlBtTGlzdA9nZA% 3D% 3D

therefore, viewstate fails.

Is there a way to override and view the view information in the urldecode view before starting?

  System.Web.HttpException: The state information is invalid for this page and might be corrupted.  ---> System.Web.UI.ViewStateException: Invalid viewstate. 
  Client IP: 65.91.116.34
  Port: 37172
  User-Agent: SCH-R430 UP.Browser / 6.2.3.8 (GUI) MMP / 2.0
  ViewState:% 2FwEPDwULLTExNTMyOTcwOTBkGAEFBlBtTGlzdA9nZA% 3D% 3D
  Referer: 
  Path: /mobile/Inbox.aspx ---> System.FormatException: Invalid character in a Base-64 string.
    at System.Convert.FromBase64String (String s)
    at System.Web.UI.ObjectStateFormatter.Deserialize (String inputString)
    at System.Web.UI.ObjectStateFormatter.System.Web.UI.IStateFormatter.Deserialize (String serializedState)
    at System.Web.UI.Util.DeserializeWithAssert (IStateFormatter formatter, String serializedState)
    at System.Web.UI.HiddenFieldPageStatePersister.Load ()
    --- End of inner exception stack trace ---
    --- End of inner exception stack trace ---
    at System.Web.UI.ViewStateException.ThrowError (Exception inner, String persistedState, String errorPageMessage, Boolean macValidationError)
    at System.Web.UI.ViewStateException.ThrowViewStateError (Exception inner, String persistedState)
    at System.Web.UI.HiddenFieldPageStatePersister.Load ()
    at System.Web.UI.Page.LoadPageStateFromPersistenceMedium ()
    at System.Web.UI.Page.LoadAllState ()
    at System.Web.UI.Page.ProcessRequestMain (Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
    at System.Web.UI.Page.ProcessRequest (Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
    at System.Web.UI.Page.ProcessRequest ()
    at System.Web.UI.Page.ProcessRequestWithNoAssert (HttpContext context)
    at System.Web.UI.Page.ProcessRequest (HttpContext context)
    at ASP.mobile_inbox_aspx.ProcessRequest (HttpContext context)
    at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute ()
    at System.Web.HttpApplication.ExecuteStep (IExecutionStep step, Boolean & completedSynchronously)
+3
source share
2 answers

You can implement a custom ViewStatePersister object that handles this. You probably want to extract it from the HiddenFieldPageStatePersister . Take a look at this article , which shows how to implement compression on top of the ViewState, but is very similar to what you need to do.

Here's a bit of a hack: you need to use reflection to set the StateFormatter field of the base class, which contrary to what the MSDN docs say is not marked as virtual, so you cannot override it without reflection.

+3
source

Use the solution below and check if it works. It works for me. Add this code to your asp.net code, which is causing the problem. Below code is in vb.net

Protected Overrides Function LoadPageStateFromPersistenceMedium() As Object Return Session("_ViewState") End Function Protected Overrides Sub SavePageStateToPersistenceMedium(viewState As Object) Session("_ViewState") = viewState End Sub 
-1
source

Source: https://habr.com/ru/post/1337218/


All Articles