2009-10-16 36 views
3

我有一個c#移動網站,並且與一些移動客戶端有問題。我在下面發佈了一個跟蹤,但基本上電話的瀏覽器或手機連接到internet url的wap網關編碼視圖狀態隱藏輸入的形式。asp.net Base-64字符串中的字符無效

/wEPDwULLTExNTMyOTcwOTBkGAEFBlBtTGlzdA9nZA ==

變得

%2FwEPDwULLTExNTMyOTcwOTBkGAEFBlBtTGlzdA9nZA%3D%3D

所以視圖狀態失敗。

有沒有辦法重寫和urldecode視圖狀態信息之前進行?

 
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

(刪除我的答案,因爲我沒有發現的「視圖狀態」位) – 2009-10-16 21:14:31

回答

3

您可以實現它處理這個自定義ViewStatePersister對象。你可能想從HiddenFieldPageStatePersister中得到它。看一看this article,它顯示瞭如何在ViewState之上實現壓縮,但與您需要執行的操作非常相似。

有參與hackiness一點點:你需要使用反射來設置StateFormatter基類,它是,相反的是在MSDN docs說,沒有標記爲虛擬的,這樣不反射無法覆蓋的領域。

-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 
+0

您需要在編程語言的問題要求提供代碼,*不*的編程語言你的選擇。 – cybermonkey 2015-12-11 19:47:55