【问题标题】:asp.net Invalid character in a Base-64 stringasp.net Base-64 字符串中的无效字符
【发布时间】:2010-12-07 12:20:43
【问题描述】:

我有一个 C# 移动站点,但某些移动客户端存在问题。我在下面发布了一条跟踪信息,但基本上是手机浏览器或手机连接到互联网 url 的 wap 网关对表单中的视图状态隐藏输入进行编码。

/wEPDwULLTExNTMyOTcwOTBkGAEFBlBtTGlzdA9nZA==

变成

%2FwEPDwULLTExNTMyOTcwOTBkGAEFBlBtTGlzdA9nZA%3D%3D

所以视图状态失败。

在处理之前是否有覆盖和 urldecode 视图状态信息?

System.Web.HttpException:此页面的状态信息无效并且可能已损坏。 ---> System.Web.UI.ViewStateException:无效的视图状态。 客户端 IP:65.91.116.34 端口:37172 用户代理:SCH-R430 UP.Browser/6.2.3.8 (GUI) MMP/2.0 视图状态:%2FwEPDwULLTExNTMyOTcwOTBkGAEFBlBtTGlzdA9nZA%3D%3D 推荐人: 路径:/mobile/Inbox.aspx ---> System.FormatException:Base-64 字符串中的无效字符。 在 System.Convert.FromBase64String(String s) 在 System.Web.UI.ObjectStateFormatter.Deserialize(字符串输入字符串) 在 System.Web.UI.ObjectStateFormatter.System.Web.UI.IStateFormatter.Deserialize(字符串序列化状态) 在 System.Web.UI.Util.DeserializeWithAssert(IStateFormatter 格式化程序,字符串序列化状态) 在 System.Web.UI.HiddenFieldPageStatePersister.Load() --- 内部异常堆栈跟踪结束 --- --- 内部异常堆栈跟踪结束 --- 在 System.Web.UI.ViewStateException.ThrowError(异常内部,字符串 persistedState,字符串 errorPageMes​​sage,布尔 macValidationError) 在 System.Web.UI.ViewStateException.ThrowViewStateError(异常内部,字符串持久状态) 在 System.Web.UI.HiddenFieldPageStatePersister.Load() 在 System.Web.UI.Page.LoadPageStateFromPersistenceMedium() 在 System.Web.UI.Page.LoadAllState() 在 System.Web.UI.Page.ProcessRequestMain(布尔 includeStagesBeforeAsyncPoint,布尔 includeStagesAfterAsyncPoint) 在 System.Web.UI.Page.ProcessRequest(布尔 includeStagesBeforeAsyncPoint,布尔 includeStagesAfterAsyncPoint) 在 System.Web.UI.Page.ProcessRequest() 在 System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext 上下文) 在 System.Web.UI.Page.ProcessRequest(HttpContext 上下文) 在 ASP.mobile_inbox_aspx.ProcessRequest(HttpContext 上下文) 在 System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() 在 System.Web.HttpApplication.ExecuteStep(IExecutionStep 步骤,Boolean& completedSynchronously)

【问题讨论】:

  • (删除了我的答案,因为我没有发现“viewstate”位)

标签: c# .net asp.net viewstate base64


【解决方案1】:

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

这涉及到一点技巧:您需要使用反射来设置StateFormatter 基类的字段,这与MSDN docs 所说的相反,没有标记为虚拟,所以不能没有反射就被覆盖。

【讨论】:

    【解决方案2】:

    使用以下解决方案并检查它是否有效。这个对我有用。将此代码添加到导致问题的 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
    

    【讨论】:

    • 您需要以问题提出的编程语言提供代码,不是您选择的编程语言。
    猜你喜欢
    • 1970-01-01
    • 2011-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多