Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Validation of viewstate MAC failed.

Posted on 2011-03-01
9
Medium Priority
?
1,308 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 9

Expert Comment

by:gdupadhyay
ID: 35009111
0
 
LVL 9

Expert Comment

by:gdupadhyay
ID: 35009179
0
 

Author Comment

by:o3h
ID: 35009243
Well that link suggests the thing that already have done...
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Expert Comment

by:gdupadhyay
ID: 35009524
0
 
LVL 9

Accepted Solution

by:
gdupadhyay earned 2000 total points
ID: 35009565
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
ID: 35009579
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
ID: 35015020
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
ID: 35015874
Solved. I hardcoded the validation key.
Like so:

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

Author Closing Comment

by:o3h
ID: 35067727
Solved
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

704 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