System.Web.HttpException: Validation of viewstate MAC failed in ASP.NET

2

I have developed an application in asp.net . Now I am trying to host it in another Server . When I run this application from that server I am getting the following error :

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. 

The stack trace is as follows :

[ViewStateException: Invalid viewstate. 
    Client IP: 10.11.201.84
    Port: 62640
    User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 10.0; WOW64; Trident/8.0; .NET4.0C; .NET4.0E; InfoPath.3; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729; .NET CLR 1.1.4322)
    ViewState: /wEPDwUKLTE4MDU5MzAwNg9kFgICAw8WAh4GYWN0aW9uBWpmYW12ZXJpZnlIb21lLmFzcHg/bmFtZT05ODkmYXBwdXNlcj0nUkFOQTAwMScmYWlsb2dpZD0nMScmZGVwYW1vdW50PSZzZXNzaWQ9JzI4OTAyMzQzMDkzMTQ1ICcmY3VzdG5vPSc5ODknZGQ43r63dbDPk+BB/tFxs4xJkThUIQ==
    Referer: http://10.11.201.170/finger/startverifyHome.aspx?name=989&ailogid='1'&appuser='RANA001'&depamount=&custno='989'&sessid='28902343093145%20'
    Path: /finger/famverifyHome.aspx]

[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.ThrowError(Exception inner, String persistedState, String errorPageMessage, Boolean macValidationError) +106
   System.Web.UI.ViewStateException.ThrowMacValidationError(Exception inner, String persistedState) +14
   System.Web.UI.ObjectStateFormatter.Deserialize(String inputString) +237
   System.Web.UI.ObjectStateFormatter.System.Web.UI.IStateFormatter.Deserialize(String serializedState) +4
   System.Web.UI.Util.DeserializeWithAssert(IStateFormatter formatter, String serializedState) +37
   System.Web.UI.HiddenFieldPageStatePersister.Load() +207
   System.Web.UI.Page.LoadPageStateFromPersistenceMedium() +105
   System.Web.UI.Page.LoadAllState() +43
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +6785
   System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +242
   System.Web.UI.Page.ProcessRequest() +80
   System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +21
   System.Web.UI.Page.ProcessRequest(HttpContext context) +49
   ASP.famverifyhome_aspx.ProcessRequest(HttpContext context) in c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\finger\7c8a0dc9\bf1de8ca\App_Web_yhgsi6y0.0.cs:0
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75

I have followed this tutorial .

  1. I have opened IIS and selected my website to get this screen :

enter image description here

  1. I have double clicked the Machine Key icon to get this screen: enter image description here

Then when I have generated the key , the following is entered in my web.config file .

<machineKey decryption="AES" decryptionKey="A9392EC7910C......CF5F8D31AD08B1E68AAEA94BEB939C" validation="SHA1" validationKey="2763A48574235661A1......21F289237DE25A14EF0EF97BCFE1A78B2F0B504E5F9021422E737F11D26CD5DD0D311F17AD93BC5E486C8907159C6252FE8C70DE" />

But still my problem is not solved . How can I solve this problem ? Please help me .

c#
asp.net
macos
asked on Stack Overflow Mar 19, 2017 by Icche Guri • edited May 23, 2017 by Community

2 Answers

1

It can also be because of this:

<httpCookies requireSSL="true" />

And you are not doing HTTPs.

answered on Stack Overflow May 14, 2018 by user2030561
0

If you are using ASP.NET 4.5 then follow the following steps:

  1. Use the following site to generate a Machine Key: http://www.blackbeltcoder.com/Resources/MachineKey.aspx
  2. Copy Full Machine Key Code.
  3. Go To your Web.Config File.
  4. Paste the Machine Key in the following code section:

Edit: enableViewStateMac=False is deprecated (ref. https://blogs.msdn.microsoft.com/webdev/2014/09/09/farewell-enableviewstatemac/)

You should not see the viewstate Mac failed error anymore. Each website in the same app pool should have a separate machine key otherwise this error will continue.

answered on Stack Overflow Mar 19, 2017 by Farhad Rakib • edited Jul 9, 2018 by Jeff Mergler

User contributions licensed under CC BY-SA 3.0