TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Craig Davis
NA
40
0
Validation of ViewState MAC failed /Timeout
Apr 24 2011 8:52 PM
My website produces this error: Validation of Viewstate MAC failed: If website is hosted by Web Farm or cluster.....
I researched this on the Internet and modified my code by:
changing my web.config file by:
<pages validateRequest="false" enableEventValidation="false" viewStateEncryptionMode ="Never" />
When this didn't work I added the the following method (coded sourced from Internet):
protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
System.IO.StringWriter stringWriter = new System.IO.StringWriter();
HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter);
base.Render(htmlWriter);
string html = stringWriter.ToString();
string[] aspnet_formelems = new string[5];
aspnet_formelems[0] = "__EVENTTARGET";
aspnet_formelems[1] = "__EVENTARGUMENT";
aspnet_formelems[2] = "__VIEWSTATE";
aspnet_formelems[3] = "__EVENTVALIDATION";
aspnet_formelems[4] = "__VIEWSTATEENCRYPTED";
foreach (string elem in aspnet_formelems)
{
//Response.Write("input type=""hidden"" name=""" & abc.ToString & """")
int StartPoint = html.IndexOf("<input type=\"hidden\" name=\"" +
elem.ToString() + "\"");
if (StartPoint >= 0)
{
//does __VIEWSTATE exist?
int EndPoint = html.IndexOf("/>", StartPoint) + 2;
string ViewStateInput = html.Substring(StartPoint, EndPoint - StartPoint);
html = html.Remove(StartPoint, EndPoint - StartPoint);
int FormStart = html.IndexOf("<form");
int EndForm = html.IndexOf(">", FormStart) + 1;
if (EndForm >= 0)
html = html.Insert(EndForm, ViewStateInput);
}
}
writer.Write(html);
}
to render the hidden viewstate form values to the top of the form so if my page loads slowly these form values get processed first and are not omitted during an event trigger. This didn't work either.
I noticed that these error messages appear when my webpages is idle after twenty minutes. Could this be a timeout issue?
Reply
Answers (
1
)
Airline Ticket reservation project into c#.NET
convert html page to PDF with out using 3 rd party controls