Validation of viewstate MAC failed when posting from a sharepoint page to a plain asp.net page

StackOverflow https://stackoverflow.com/questions/19113937

  •  30-06-2022
  •  | 
  •  

Question

I have this small page:

<%@ 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>

And this page has the simple job of saving files that are posted to it (some through javascript, others are posted by a daemon). As you can see, there are no server controls because there is no need for it. So viewstate validation was disabled by setting EnableViewStateMac to false (at least that's what I think it does). It used to work fine until recently. Now I started getting this error:

<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>

There were no changes to the code. I am not sure yet if it was caused by an update or something. I also read that setting EnableViewState is a no no: https://stackoverflow.com/a/14210118/642269

Is there anyway I can workaround this? I really DON'T need view state for this page, but the rest of the site is using it. Is there any way to turn this off just for this specific page? UPDATE: The page that is failing to post is a sharepoint page. The sharepoint page has an upload control that makes an async upload through an iframe to this page (the page I posted above). It only fails when posting from the said sharepoint page. As a workaround, I created another form and posted using this form. There's probably a field in the main form that triggers a MAC validation or something.

Was it helpful?

Solution

I believe the exception gives you a hint as how to resolve the issue. Each server in the farm should have the same machineKey settings so that one server can decrypt the view state from the other machine.

OTHER TIPS

I had the same error but suggested solutions on the net didn't work. Lost some hours until I realized I didn't restart my browser after restarting IIS (due to some config changes). So the problem was resolved after I restarted my browser.

I guess the viewstate becomes invalid once IIS is restarted.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top