asp.net Base-64字符串中的字符无效

我有一个移动网站,并且有一些移动客户端存在问题。 我已经在下面发布了一条跟踪,但基本上是手机或wap网关的浏览器,手机连接到互联网url,在窗体中编码viewstate隐藏输入。

/ wEPDwULLTExNTMyOTcwOTBkGAEFBlBtTGlzdA9nZA ==

%2FwEPDwULLTExNTMyOTcwOTBkGAEFBlBtTGlzdA9nZA%3D%3D

所以viewstate失败了。

无论如何在进行处理之前覆盖和urldecode viewstate信息?

 System.Web.HttpException:状态信息对于此页面无效,可能已损坏。  ---> System.Web.UI.ViewStateException:无效的viewstate。 
 客户IP:65.91.116.34
 港口:37172
 用户代理:SCH-R430 UP.Browser / 6.2.3.8(GUI)MMP / 2.0
  ViewState:%2FwEPDwULLTExNTMyOTcwOTBkGAEFBlBtTGlzdA9nZA%3D%3D
 引用站点: 
 路径:/mobile/Inbox.aspx ---> System.FormatException:Base-64字符串中的字符无效。
   在System.Convert.FromBase64String(String s)
   在System.Web.UI.ObjectStateFormatter.Deserialize(String inputString)
   在System.Web.UI.ObjectStateFormatter.System.Web.UI.IStateFormatter.Deserialize(String serializedState)
   在System.Web.UI.Util.DeserializeWithAssert(IStateFormatter formatter,String serializedState)
   在System.Web.UI.HiddenFieldPageStatePersister.Load()
    ---内部exception堆栈跟踪结束---
    ---内部exception堆栈跟踪结束---
   在System.Web.UI.ViewStateException.ThrowError(Exception inner,String persistedState,String errorPageMes​​sage,Boolean macValidationError)
   在System.Web.UI.ViewStateException.ThrowViewStateError(Exception inner,String persistedState)
   在System.Web.UI.HiddenFieldPageStatePersister.Load()
   在System.Web.UI.Page.LoadPageStateFromPersistenceMedium()
   在System.Web.UI.Page.LoadAllState()
   在System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint)
   在System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint)
   在System.Web.UI.Page.ProcessRequest()
   在System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)
   在System.Web.UI.Page.ProcessRequest(HttpContext上下文)
    at ASP.mobile_inbox_aspx.ProcessRequest(HttpContext context)
   在System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   在System.Web.HttpApplication.ExecuteStep(IExecutionStep step,Boolean&completedSynchronously)

您可以实现一个处理此问题的自定义ViewStatePersister对象。 您可能希望从HiddenFieldPageStatePersister派生它。 看一下本文 ,它展示了如何在ViewState之上实现压缩,但与您需要做的非常相似。

涉及到一些hackiness:你需要使用reflection来设置StateFormatter基类的字段,这与MSDN文档所说的相反,没有标记为虚拟,因此如果没有reflection则无法覆盖。

使用以下解决方案并检查它是否有效。 这个对我有用。 在您的asp.net代码中添加此代码,这会导致问题。 下面的代码在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