Link to home
Start Free TrialLog in
Avatar of o3h
o3h

asked on

Validation of viewstate MAC failed.

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.
Avatar of gdupadhyay
gdupadhyay
Flag of United States of America image

Avatar of o3h
o3h

ASKER

Well that link suggests the thing that already have done...
ASKER CERTIFIED SOLUTION
Avatar of gdupadhyay
gdupadhyay
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
try to add this string in <system.web> section of your web.config file :
<pages validateRequest="false" enableEventValidation="false" viewStateEncryptionMode ="Never" />

Avatar of o3h

ASKER

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

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of o3h

ASKER

Solved