问题
I have developed application and its working fine on local with remote DB connection but when its put on live server on every post back event its giving this exception:
Server Error in '/openlearningsolutions' 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:
[No relevant source lines]
Source File: c:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\openlearningsolutions\75c7e45d\68c7418e\App_Web_admin.aspx.cdcab7d2.ff0f08dc.0.cs Line: 0
Stack Trace:
[ViewStateException: Invalid viewstate.
Client IP: 182.177.92.68
Port: 18076
Referer: http://www.projects.azexsolutions.com/openlearningsolutions/admin.aspx
Path: /openlearningsolutions/admin.aspx
User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20100101 Firefox/17.0
ViewState: /wEPDwUKMjAzNzcxOTA4Ng9kFgICAw8WAh4HZW5jdHlwZQUTbXVsdGlwYXJ0L2Zvcm0tZGF0YRYMAhEPZBYCAgUPEA8WBh4NRGF0YVRleHRGaWVsZAUKY291cnNlTmFtZR4ORGF0YVZhbHVlRmllbGQFCGNvdXJzZUlEHgtfIURhdGFCb3VuZGdkEBUAFQAUKwMAZGQCFQ9kFgICBQ8QDxYGHwEFCmNvdXJzZU5hbWUfAgUIY291cnNlSUQfA2dkEBUAFQAUKwMAFgBkAhkPZBYEAgUPEA8WBh8BBQpjb3Vyc2VOYW1lHwIFCGNvdXJzZUlEHwNnZBAVAQZTZWxlY3QVAQZTZWxlY3QUKwMBZxYBZmQCBw8QZGQWAGQCHQ9kFgICAQ8QDxYGHwEFCmNvdXJzZU5hbWUfAgUIY291cnNlSUQfA2dkEBUBDVNlbGVjdCBDb3Vyc2UVAQ1TZWxlY3QgQ291cnNlFCsDAWdkZAIhD2QWBgIBDxAPFgYfAQUKY291cnNlTmFtZR8CBQhjb3Vyc2VJRB8DZ2QQFQAVABQrAwAWAGQCAw8QZGQWAGQCCQ9kFgICAQ8WAh4Fc3R5bGUFxQJiYWNrZ3JvdW5kOnVybCgvb3BlbmxlYXJuaW5nc29sdXRpb25zL1dlYlJlc291cmNlLmF4ZD9kPU1VcVk1UGwybTBtNTJnRUI4a0JBOGJ0WTBiLW9hSWNxWmc1cVU3MjZGRUtEMzJYbnpsRTQ4XzBwUjhJSjVHYV...]
[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) +235
System.Web.UI.ViewStateException.ThrowMacValidationError(Exception inner, String persistedState) +14
System.Web.UI.ObjectStateFormatter.Deserialize(String inputString) +274
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() +241
System.Web.UI.Page.LoadPageStateFromPersistenceMedium() +106
System.Web.UI.Page.LoadAllState() +43
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +8431
System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +253
System.Web.UI.Page.ProcessRequest() +78
System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +21
System.Web.UI.Page.ProcessRequest(HttpContext context) +49
ASP.admin_aspx.ProcessRequest(HttpContext context) in c:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\openlearningsolutions\75c7e45d\68c7418e\App_Web_admin.aspx.cdcab7d2.ff0f08dc.0.cs:0
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +100
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272
Why am i getting this error on server but on local host its working fine?
回答1:
I added this line in web.config under and it worked for me:
<machineKey validationKey="ED69AB3D81E3E1CFBE24D3910DDCD3DAFD0919466CD7D442D45E33BCEF2A72DB26CFDDF390D843EF4AB6A2A4C7DA6F23327C0482EA1CF67AF41B188F495D7112" decryptionKey="B114854371A664138153F7A0605108B09E1E871CC112C7873AD2F58C158D11FC" validation="SHA1" decryption="AES" />
来源:https://stackoverflow.com/questions/14191481/validation-of-mac-failed