Solved

Validation of viewstate MAC failed.

Posted on 2011-03-01
9
1,226 Views
Last Modified: 2012-05-11
Hi im using .NET 4.0 on a single IIS 7.0, no web farm or cluster.

When a page has been "idle" for about 10 minutes I get the following error when doing something that generates a postback, for example clicking a button:

Server Error in '/' Application.
--------------------------------------------------------------------------------

Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster. 
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: Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.

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: 


[HttpException (0x80004005): Unable to validate data.]
   System.Web.Configuration.MachineKeySection.GetDecodedData(Byte[] buf, Byte[] modifier, Int32 start, Int32 length, Int32& dataLength) +390
   System.Web.UI.ObjectStateFormatter.Deserialize(String inputString) +279

[ViewStateException: Invalid viewstate. 
	Client IP: 2a01:2b0:3009:231:8dcd:9757:105:5908
	Port: 65262
	Referer: http://utvsrv115/EditProfile/Competence/Competencies.aspx?requestedUserName=roh@nethouse.local
	Path: /EditProfile/Competence/Competencies.aspx
	User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/4.0; GTB6.6; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; MS-RTC LM 8; InfoPath.3; .NET4.0E)
	ViewState: /wEPDwULLTEyMDcwNjcxODAPZBYCZg9kFgJmD2QWAgIDD2QWBAIBDxQrAAgPFgYeDEVtcHR5TWVzc2FnZQUZU8O2ayBpIGtvbXBldGVuc2RhdGFiYXNlbh4XRW5hYmxlQWpheFNraW5SZW5kZXJpbmdoHg1MYWJlbENzc0NsYXNzBQdyaUxhYmVsFgIeCm9uS2V5UHJlc3MFU2phdmFzY3JpcHQ6aWYgKGV2ZW50LmtleUNvZGUgPT0gMTMpIF9fZG9Qb3N0QmFjaygnY3RsMDAkY3RsMDAkU2VhcmNoTGlua0J1dHRvbicsJycpFgYeBVdpZHRoGwAAAAAAwGJAAQAAAB4IQ3NzQ2xhc3MFEXJpVGV4dEJveCByaUhvdmVyHgRfIVNCAoICFgYfBBsAAAAAAMBiQAEAAAAfBQURcmlUZXh0Qm94IHJpRXJyb3IfBgKCAhYGHwQbAAAAAADAYkABAAAAHwUFE3JpVGV4dEJveCByaUZvY3VzZWQfBgKCAhYGHwQbAAAAAADAYkABAAAAHwUFE3JpVGV4dEJveCByaUVuY...]

[HttpException (0x80004005): Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.]
   System.Web.UI.ViewStateException.ThrowMacValidationError(Exception inner, String persistedState) +11193188
   System.Web.UI.ObjectStateFormatter.Deserialize(String inputString) +11193607
   System.Web.UI.Util.DeserializeWithAssert(IStateFormatter formatter, String serializedState) +60
   System.Web.UI.HiddenFieldPageStatePersister.Load() +11193879
   System.Web.UI.Page.LoadPageStateFromPersistenceMedium() +11271111
   System.Web.UI.Page.LoadAllState() +52
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +11265679
   System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +11265198
   System.Web.UI.Page.ProcessRequest() +119
   System.Web.UI.Page.ProcessRequest(HttpContext context) +167
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +597
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +266

 


--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1 

Open in new window


After reading some forums I have also added the following:
<pages validateRequest="false" enableEventValidation="false" viewStateEncryptionMode="Never"> but to no help.

Open in new window


Please help.
0
Comment
Question by:o3h
  • 5
  • 4
9 Comments
 
LVL 9

Expert Comment

by:gdupadhyay
Comment Utility
0
 
LVL 9

Expert Comment

by:gdupadhyay
Comment Utility
0
 

Author Comment

by:o3h
Comment Utility
Well that link suggests the thing that already have done...
0
 
LVL 9

Expert Comment

by:gdupadhyay
Comment Utility
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 9

Accepted Solution

by:
gdupadhyay earned 500 total points
Comment Utility
There is no single reason for this error, So we have to verify all condition.

where you added :
<pages validateRequest="false" enableEventValidation="false" viewStateEncryptionMode="Never">

I found one expert-exchange solution.
http://www.experts-exchange.com/Programming/Languages/.NET/Q_22657123.html

0
 
LVL 9

Expert Comment

by:gdupadhyay
Comment Utility
try to add this string in <system.web> section of your web.config file :
<pages validateRequest="false" enableEventValidation="false" viewStateEncryptionMode ="Never" />

0
 

Author Comment

by:o3h
Comment Utility
gdupadhyay: have tried it all.
Also have added <pages validateRequest="false" enableEventValidation="false" viewStateEncryptionMode ="Never" /> as you can see in my original post.

BUT, none of the posts I have read do not have the same problem as I do. I only get the error when the page has been idle for about 10-15mins, could it have anything todo with sessions? Im not too good with this...
Thank you.
Post my web.config, if it could be to nay help.

<?xml version="1.0"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <appSettings>
    <add key="ChartImageHandler" value="storage=file;timeout=20;" />
  </appSettings>
  <connectionStrings>
  
    <add name="KompDBEntitiesContainer" connectionString="metadata=res://*/KompDBEFModel.csdl|res://*/KompDBEFModel.ssdl|res://*/KompDBEFModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=utvsrv115;Initial Catalog=KompDBKonfReal;User Id=komghpdb;Pwd=dghg&quot;" providerName="System.Data.EntityClient"/>

  </connectionStrings>
  <system.web>
    <customErrors mode="Off"></customErrors>
    <pages validateRequest="false" enableEventValidation="false" viewStateEncryptionMode="Never">
      <controls>
        <add tagPrefix="telerik" namespace="Telerik.Web.UI" assembly="Telerik.Web.UI" />
        <add tagPrefix="asp" namespace="System.Web.UI.DataVisualization.Charting"
         assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
      </controls>
    </pages>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
        <add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
        <add assembly="System.Speech, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add assembly="System.Web.Extensions.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add assembly="System.Web.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
        <add assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      </assemblies>
    </compilation>
    <authentication mode="Windows"/>
 
    <authorization>
    
      <allow users="*"/>
    </authorization>
  
    <membership>
      <providers>
        <clear/>
        <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/"/>
      </providers>
    </membership>
    <profile>
      <providers>
        <clear/>
        <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
      </providers>
    </profile>
   
    <roleManager defaultProvider="WindowsProvider" enabled="true" cacheRolesInCookie="false">
      <providers>
        <add name="WindowsProvider" type="System.Web.Security.WindowsTokenRoleProvider"/>
      </providers>
    </roleManager>
    <httpHandlers>
      <add path="Telerik.Web.UI.WebResource.axd" verb="*" type="Telerik.Web.UI.WebResource"
       validate="false" />
      <add path="ChartImg.axd" verb="GET,HEAD,POST" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
       validate="false" />
    </httpHandlers>
  </system.web>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <validation validateIntegratedModeConfiguration="false" />
    <handlers>
      <remove name="ChartImageHandler" />
      <add name="Telerik_Web_UI_WebResource_axd" verb="*" preCondition="integratedMode"
       path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource" />
      <add name="ChartImageHandler" preCondition="integratedMode" verb="GET,HEAD,POST"
       path="ChartImg.axd" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    </handlers>
  </system.webServer>
</configuration>

Open in new window

0
 

Assisted Solution

by:o3h
o3h earned 0 total points
Comment Utility
Solved. I hardcoded the validation key.
Like so:

  <machineKey
validationKey="3ADC71AB988C34ED0E834AF43C11B42DA6F4FDCA3B8E558CF585851DC3A39D44FB0F2DE01C715F1B0FBEC309C6D5299084E4C0BAB593005628959CE8C688A122"
decryptionKey="AA6DC22BF2281909AC6DF69746FD951EDF057F56F3A13B8CF50CD45665A81E62"
validation="SHA1" decryption="AES" />
0
 

Author Closing Comment

by:o3h
Comment Utility
Solved
0

Featured Post

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Prologue It is often required to host multiple websites on a single instance of IIS, mostly in development environments instead of on production servers. I am sure it is not much a preferred solution on production servers but this is at least a pos…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now