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 .

Community
  • 1
  • 1
Christopher Marlowe
  • 2,098
  • 6
  • 38
  • 68

2 Answers2

1

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.

Jeff Mergler
  • 1,384
  • 20
  • 27
Farhad Rakib
  • 162
  • 1
  • 14
  • NEVER use a public resource to generate a Machine Key: See https://support.microsoft.com/en-us/help/2915218/resolving-view-state-message-authentication-code-mac-errors, Appendix A "Appendix A: How to generate a element" – Marcel May 03 '17 at 09:31
1

It can also be because of this:

<httpCookies requireSSL="true" />

And you are not doing HTTPs.

user2030561
  • 99
  • 1
  • 2
  • Confirmed. In my local development environment, unless you specifically set https in your project properties (its common/default to use http when hitting F5 or Ctrl F5 in Visual Studio) I was getting the error. When I set `` with http I got the error. When I changed my project properties to use https the error did not appear. When I changed `requireSSL="false"` with http, the error did not appear. – Jeff Mergler Jul 09 '18 at 17:18