gpt4 book ai didi

c# - 回发时 IE 中的 ViewState 错误

转载 作者:太空宇宙 更新时间:2023-11-03 16:25:25 25 4
gpt4 key购买 nike

我目前正在开发一个在 Sharepoint 中运行的 ASP.Net 网站。在解决问题之前,让我先给您一些背景信息。

我开发了 UserControl,然后将其添加为共享点页面上的 Web 部件。其中一些 Web 部件会在加载共享点页面时动态加载。

我们是这样做的:

  • 创建一个应用程序页面 (InfoPage),将实际的用户控件加载到应用程序页面中

<form id="frmInfoPage" runat="server"> <div id="infopage" runat="server"></div> </form>

  • 创建一个 UserControl (InfoContainer),使用以下代码抓取“InfoPage”并将其添加到“InfoContainer”中的一个 div 中:
        <div id="InfoContainerDiv"/>            <script language="javascript" type="text/javascript">            var numRando = Math.floor(Math.random() * 101);            $("#InfoContainerDiv").load("url of application page"<%=Query%>&rndNum=" + numRando);        </script>
  • So then this container is put into the SharePoint page...

So the problem is that when the sharepoint page renders, there will be 3 __VIEWSTATE hidden fields (2 for the dynamically loaded controls and the SP page), which IE7-9 will concatenate with a comma. i.e. /WSteyxeetYRduiylgkdxr,TUIFbiygutifTUfuvFufVvIUCF,ITcvuVuyfIYRCTECOBPOUIBHv

This causes an error on postbacks when the server tries to decode the ViewState:

<pre lang="HTML">
The state information is invalid for this page and might be corrupted.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: The state information is invalid for this page and might be corrupted.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[FormatException: Invalid character in a Base-64 string.]
System.Convert.FromBase64String(String s) +0
System.Web.UI.ObjectStateFormatter.Deserialize(String inputString) +98
System.Web.UI.ClientScriptManager.EnsureEventValidationFieldLoaded() +205

[ViewStateException: Invalid viewstate.
Client IP: 10.0.0.2
Port: 52270
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)
ViewState: /wEWOAKyz/ClDQKu1K/fBQLCl57WAQL2s5oZArGPqIAOAp20leQEArOq47oIAuqkk+UGArr75pUEAo3A5PMBAq/69ZkHAqTPzZIBArKB/tECAund0sECAoOVssUPAsbZv7cGAtKIwsUDAqzJytwCAvLwypMPApedlMsPAsb2uIYDAqq989YCAoyOwIYBAurogPQDAqb55aEOApWatccBArCN1+wLAvqjl7IPAsbemgcCq+T48Q0CnKjesQwCt4PAxgYCgumAmA4CgumEmA4CvcCmLQL6o5uyDwK9wKItAqvk/PENAsbengcC4bGArAoC4bG8rAoCnKiisQwCmZKdzAIC2tuR7gICk7OHrQYCvZqnwAEChe3tiAECq5rv3AIC69aW+gkCsaHYzAgC2/SjjgwCoprfugkC98TR6AwCho29jgcC3LrdswwChpymvwM=,/wEWAwLv25y/BQLPi+juDQK8wrfPAQ==,/wEWEQLv25y/BQKV1/6iBwL5ivP7BgKF5rW2DgLkv7KzBQKt56yyBwL0x6mvBgK35/ixAQL23cvUDgLk5ryLCgKfw/3jDAL7wZyxBgKosZu6CAK66OGUCQKHyrWLCQLUyPmPCQKBpr2SCQ==
Referer: blablabla

[HttpException (0x80004005): The state information is invalid for this page and might be corrupted.]
System.Web.UI.ViewStateException.ThrowError(Exception inner, String persistedState, String errorPageMessage, Boolean macValidationError) +148
System.Web.UI.ClientScriptManager.EnsureEventValidationFieldLoaded() +10946558
System.Web.UI.ClientScriptManager.ValidateEvent(String uniqueId, String argument) +64
System.Web.UI.WebControls.HiddenField.LoadPostData(String postDataKey, NameValueCollection postCollection) +62
System.Web.UI.Page.ProcessPostData(NameValueCollection postData, Boolean fBeforeLoad) +507
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +11042743
System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +11042282
System.Web.UI.Page.ProcessRequest() +91
System.Web.UI.Page.ProcessRequest(HttpContext context) +240
Microsoft.SharePoint.Publishing.TemplateRedirectionPage.ProcessRequest(HttpContext context) +175
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +599
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +171</pre>

我尝试过的:

  • 禁用所有控件上的 EnableViewstate(__VIEWSTATE 隐藏字段仍然存在)
  • 删除 Page_Init 上的 __VIEWSTATE 字段(这会导致 ViewStateMac 错误)
  • 将 View 状态加密模式设置为“从不”(没有区别)
  • 在配置中禁用和加密以及 viewstateMac。 (获取 SessionState 错误)

有人可以给我一些意见/建议吗我希望我提供了足够的信息,而且我想了解这个问题,而不仅仅是用另一种方式来解决...由于以前的共享点问题,设计就像这样。

谢谢。

最佳答案

您可以使用 LoadPageStateFromPersistenceMedium() 对 View 状态进行自定义反序列化,其中包含分隔其“,”的逗号| System.Web.UI.Page 的功能作为:

private ObjectStateFormatter _formatter = new ObjectStateFormatter();

protected override object LoadPageStateFromPersistenceMedium()
{
// fix here and load your ViewState on correct way
string vsString = Request.Form["__VIEWSTATE"];

return _formatter.Deserialize(vsString);
}

这只是一个想法,您需要调试并使用它来解决您的问题。

关于c# - 回发时 IE 中的 ViewState 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12731770/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com