2

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

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

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

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

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

  • 创建一个用户控件(InfoContainer),它会抓取“InfoPage”并将其添加到“InfoContainer”中的 div 中,使用以下代码:
        <div id="InfoContainerDiv"/>    


        <script language="javascript" type="text/javascript">
            var numRando = Math.floor(Math.random() * 101);
            $("#InfoContainerDiv").load("应用页面的url"<%=Query%>&rndNum=" + numRando);
        </脚本>
  • 那么这个容器被放入 SharePoint 页面......

所以问题是,当sharepoint页面渲染时,会有3个__VIEWSTATE隐藏字段(2个用于动态加载的控件和SP页面),IE7-9会用逗号连接起来。即 /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 错误)
  • 将视图状态加密模式设置为“从不”(没有区别)
  • 在配置中禁用和加密以及 viewstateMac。(获取 SessionState 错误)

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

谢谢你。

4

2 回答 2

0

LoadPageStateFromPersistenceMedium()您可以使用 as 的函数对视图状态进行自定义反序列化,其中包含打破其“,”的逗号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);
}

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

于 2012-10-04T17:06:52.547 回答
0

添加回调以删除额外的 ViewState 隐藏字段: $("#InfoContainerDiv").load("应用程序页面的 url"<%=Query%>&rndNum=" + numRando, function() {删除动态加载的 VIEWSTATE 隐藏字段。 }) ;

于 2012-10-07T08:37:08.467 回答