Failed to verify viewstate MAC address. - Not on a web farm, occurs when a button is clicked

I saw that this question asked a lot, but none of the questions or answers that I saw seem to affect my problem. As the name implies, I always get a nice viewstate error check.

My company’s site is hosted on Amazon EC2, so as far as I know, this is not a web farm, as this is the only page that has a problem.

We have a simple feedback page that looks great, and all the elements on the page work just fine, including leaving new reviews. However, the Check Flag button generates a viewstate error when clicked.

The actual code that runs when the button is clicked is as follows:

protected void btnFlagReview_Click(object sender, EventArgs e) { try { LinkButton btn = (LinkButton)sender; int id = Int32.Parse(btn.Attributes["rid"]); testimonials.updateModerated(false, id); MailMessage mail = new MailMessage(); mail.To.Add(" oursupport@emailaddress.com "); mail.From = new MailAddress(" ourwebmaster@emailaddress.com "); mail.Subject = "A review has been flagged for moderation"; string Body = "A user review has been flagged for moderation. Please Approve/Delete this review in the Admin Panel. "; mail.Body = Body; SmtpClient smtp = new SmtpClient(); try { smtp.Send(mail); } catch (SmtpException ex) { if (ex.StatusCode == SmtpStatusCode.InsufficientStorage) smtp.Send(mail);//Send again to ensure this email gets sent } string script = "<SCRIPT type='text/javascript'>alert('This review has been flagged for moderation.')</SCRIPT>"; Type t = typeof(String); ClientScript.RegisterStartupScript(t, "Script", script); } catch(Exception ee) { businessName.Text = ee.ToString(); } } 

The code from the actual button is as follows:

 <asp:LinkButton ID="btnFlagReview" OnClick="btnFlagReview_Click" rid='<%# Eval("testimonialID") %>' runat="server">flag</asp:LinkButton> 

I even tried the solution I found on other questions on the Internet, and here, like changing the validateRequest, enableEventValidation and viewStateEncryptionMode pages to see if they will work.

I am at a loss, given that the action of the flag review is so simple compared to what we do. Any help would be greatly appreciated.

+4
source share
2 answers

I had a similar problem once and it ended up having an action attribute in the form tag. Check if you have it, and if so, delete it.

+4
source

In my comment, I asked which version of the structure you are using. The reason is that several corrections have been made to mitigate this problem.

See http://blogs.msdn.com/b/tom/archive/2008/03/14/validation-of-viewstate-mac-failed-error.aspx

Many of them seem to boil down to someone clicking a button or link on a page that is not fully returned to the browser. What seems likely in your situation for a link called a "flag" ...

The first thing to try is to use all updated windows. After that, you may need to do something like a machine key in the web.config file or create a base page class that emits the corresponding hidden fields at the top of the form, and not at the end.

===== UPDATE based on comments on the question =====

See: http://support.microsoft.com/kb/316920/

The server.transfer server itself may cause a problem. Check out this code for information to see if it applies and how to get around it.

+2
source

All Articles