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
Solved

Validation of viewstate MAC failed.

Posted on 2011-03-01
9
1,243 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
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
A phishing scam that claims a recipient’s credit card details have been “suspended” is the latest trend in spoof emails.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

808 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