回发时IE中的ViewState错误

时间:2012-10-04 16:35:04

标签: c# asp.net sharepoint user-controls viewstate

我目前正在使用Sharepoint运行的ASP.Net网站。 在我遇到问题之前,让我给你一些背景信息..

我开发了UserControls,然后将其添加到sharepoint页面上的webparts。 其中一些webparts在sharepoint页面加载时动态加载。

这就是我们这样做的方式:

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

< form id =“frmInfoPage”runat =“server”>       < div id =“infopage”runat =“server”>< / div>       < /形式>

  • 创建一个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>
  • 然后将此容器放入SharePoint页面......

所以问题是当sharepoint页面呈现时,会有3个__VIEWSTATE隐藏字段(2个用于动态加载的控件和SP页面),IE7-9将用逗号连接。 ie / WSteyxeetYRduiylgkdxr,TUIFbiygutifTUfuvFufVvIUCF,ITcvuVuyfIYRCTECOBPOUIBHv

当服务器尝试解码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错误)
  • 将viewstate加密模式设置为'never'(没有区别)
  • 在配置中禁用和加密以及viewstateMac。 (获取SessionState错误)

有人可以给我一些意见/建议 我希望我提供了足够的信息,而且,我想要理解这个问题而不仅仅是以另一种方式做到这一点......设计就像以前的sharepoint问题一样。

谢谢。

2 个答案:

答案 0 :(得分:0)

您可以使用LoadPageStateFromPersistenceMedium()的{​​{1}}函数对您的视图状态进行自定义反序列化,其中包含打破其','的逗号:

System.Web.UI.Page

这只是一个想法,你需要调试,并使用它来使它适用于你的问题。

答案 1 :(得分:0)

添加回调以删除其他ViewState隐藏字段: $(“#InfoContainerDiv”)。load(“应用程序页面的网址”&lt;%=查询%&gt;&amp; rndNum =“+ numRando,function(){删除动态加载的VIEWSTATE隐藏字段。 });