I have a c# mobile site and have a problem with some of mobile clients. I have posted a trace below but basically browser of phone or wap gateway that phone connects to internet url encodes viewstate hidden input in the form.
我有一个c#移动站点,我和一些移动客户有问题。我已经发布了一个trace命令,但基本上是手机或wap网关的浏览器连接到互联网url编码viewstate隐藏输入的表单。
/wEPDwULLTExNTMyOTcwOTBkGAEFBlBtTGlzdA9nZA==
/ wEPDwULLTExNTMyOTcwOTBkGAEFBlBtTGlzdA9nZA = =
becomes
就变成了
%2FwEPDwULLTExNTMyOTcwOTBkGAEFBlBtTGlzdA9nZA%3D%3D
% 2 fwepdwulltexntmyotcwotbkgaefblbttglzda9nza % 3 d % 3 d
so viewstate fails.
因此,视图状态失败。
Is there anyway to override and urldecode viewstate info before proccessing?
在处理之前,是否有必要重写和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)
2 个解决方案
#1
3
You can implement a custom ViewStatePersister object which handles this. You probably want to derive it from HiddenFieldPageStatePersister. Take a look at this article which shows how to implement compression on top of ViewState, but is very similar to what you need to do.
您可以实现一个自定义ViewStatePersister对象,它可以处理这个问题。您可能想从HiddenFieldPageStatePersister派生它。看看这篇文章,它展示了如何在ViewState之上实现压缩,但是与您需要做的非常相似。
There's a little bit of hackiness involved: you'll need to use reflection to set a field of the StateFormatter base class which is, contrary to what the MSDN docs say, not marked as virtual so can't be overridden without reflection.
这里有一点麻烦:您需要使用反射来设置StateFormatter基类的一个字段,与MSDN文档所说的相反,该字段没有被标记为virtual,因此没有反射就不能重写。
#2
-1
Use below solution and check if it works. It works for me. Add this code in your asp.net code behind which is causing the issue. Below code is in vb.net
使用下面的解决方案并检查它是否有效。它适合我。将此代码添加到您的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
#1
3
You can implement a custom ViewStatePersister object which handles this. You probably want to derive it from HiddenFieldPageStatePersister. Take a look at this article which shows how to implement compression on top of ViewState, but is very similar to what you need to do.
您可以实现一个自定义ViewStatePersister对象,它可以处理这个问题。您可能想从HiddenFieldPageStatePersister派生它。看看这篇文章,它展示了如何在ViewState之上实现压缩,但是与您需要做的非常相似。
There's a little bit of hackiness involved: you'll need to use reflection to set a field of the StateFormatter base class which is, contrary to what the MSDN docs say, not marked as virtual so can't be overridden without reflection.
这里有一点麻烦:您需要使用反射来设置StateFormatter基类的一个字段,与MSDN文档所说的相反,该字段没有被标记为virtual,因此没有反射就不能重写。
#2
-1
Use below solution and check if it works. It works for me. Add this code in your asp.net code behind which is causing the issue. Below code is in vb.net
使用下面的解决方案并检查它是否有效。它适合我。将此代码添加到您的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