我有一个c#移动网站,并且某些移动客户端出现问题。我已经在下面发布了一条跟踪,但基本上是手机或wap网关的浏览器,手机连接到互联网网址,对表格中的viewstate隐藏输入进行编码。
/ wEPDwULLTExNTMyOTcwOTBkGAEFBlBtTGlzdA9nZA ==
变为
%2FwEPDwULLTExNTMyOTcwOTBkGAEFBlBtTGlzdA9nZA%3D%3D
所以viewstate失败了。
在进行处理之前是否有覆盖和urldecode viewstate信息?
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)
答案 0 :(得分:3)
您可以实现一个处理此问题的自定义ViewStatePersister对象。您可能希望从HiddenFieldPageStatePersister派生它。看看this article,它展示了如何在ViewState之上实现压缩,但与您需要做的非常相似。
涉及到一些hackiness:你需要使用反射来设置StateFormatter基类的字段,这与MSDN docs所说的相反,没有标记为虚拟的没有反思就不能被覆盖。
答案 1 :(得分:-1)
使用以下解决方案并检查其是否有效。这个对我有用。在您的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