从sharepoint页面发布到普通的asp.net页面时,viewstate MAC的验证失败

时间:2013-10-01 10:31:34

标签: asp.net viewstate

我有这个小页面:

<%@ Page Language="C#" AutoEventWireup="true" Inherits="Company.Pages.Uploader" EnableViewStateMac="false"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
    <form id="form1" class="form-uploader" runat="server">
    <div>
        <pre id="jsonSpanContainer" runat="server" class="jsonDataContainer"></pre>          
    </div>
    </form>
</body>
</html>

此页面可以简单地保存发布到它的文件(一些通过javascript,其他通过守护程序发布)。如您所见,没有服务器控件,因为不需要它。因此,通过将EnableViewStateMac设置为false(至少这是我认为的那样)来禁用viewstate验证。它过去一直很好,直到最近。现在我开始收到此错误:

<span><H1>Server Error in '/' Application.<hr width=100% size=1 color=silver></H1>

<h2> <i>Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that &lt;machineKey&gt; configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.</i> </h2></span>

<font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif ">

<b> Description: </b>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.

<b> Exception Details: </b>System.Web.HttpException: Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that &lt;machineKey&gt; configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.<br><br>

代码没有变化。我不确定它是否是由更新或其他原因造成的。我还读到设置EnableViewState是否定的:https://stackoverflow.com/a/14210118/642269

无论如何我可以解决这个问题吗?我真的不需要这个页面的视图状态,但网站的其余部分正在使用它。有没有办法只为这个特定的页面关闭它? 更新: 未能发布的页面是一个sharepoint页面。 sharepoint页面有一个上传控件,可以通过iframe异步上传到此页面(我上面发布的页面)。它只在从所述sharepoint页面发布时失败。作为一种解决方法,我创建了另一个表单并使用此表单发布。主窗体中可能有一个触发MAC验证的字段。

2 个答案:

答案 0 :(得分:0)

我相信该异常会为您提供有关如何解决此问题的提示。服务器场中的每个服务器都应具有相同的machineKey设置,以便一台服务器可以从另一台计算机解密视图状态。

答案 1 :(得分:0)

我遇到了同样的错误,但建议网上的解决方案不起作用。丢失了几个小时,直到我意识到重启IIS后没有重新启动浏览器(由于一些配置更改)。所以我重新启动浏览器后问题得以解决

我想重启IIS后,viewstate会变为无效。