Solved

Validation of viewstate MAC failed.

Posted on 2011-03-01
9
1,262 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 9

Expert Comment

by:gdupadhyay
ID: 35009524
0
 
LVL 9

Accepted Solution

by:
gdupadhyay earned 500 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

Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

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.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

752 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