Visual Studio .NET - Getting error on hosted server with ASP NET 2 0

Asked By ben beethe
05-Aug-05 12:33 PM
Using ASP.NET 2.0.

I am getting the following error when trying to login to my webapp using the new Login controls in ASP.NET 2.0.  My hosting company is not sure what to do at this point.  Any ideas?

Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that 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 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) +2524520
System.Web.UI.ObjectStateFormatter.Deserialize(String inputString) +184

[ViewStateException: Invalid viewstate. 
Client IP: 208.49.199.5
Port: 35574
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50215)
ViewState: /wEPDwUKLTk4MDM0NDMyMg9kFgJmD2QWAgIDD2QWAgIDD2QWAgIBDzwrAAoBAA8WAh4IVXNlck5hbWUFB2JiZWV0aGVkZBgBBR5fX0NvbnRyb2xzUmVxdWlyZVBvc3RCYWNrS2V5X18WAgUrY3RsMDAkQ29udGVudFBsYWNlSG9sZGVyMSRMb2dpbjEkUmVtZW1iZXJNZQUxY3RsMDAkQ29udGVudFBsYWNlSG9sZGVyMSRMb2dpbjEkTG9naW5JbWFnZUJ1dHRvbouSt+L64m+K0zk04G5MXQa2+0IA
Referer: http://classes.beethe.net/login.aspx?ReturnUrl=%2fDefault.aspx
Path: /login.aspx]

[HttpException (0x80004005): Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that 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) +116
System.Web.UI.ObjectStateFormatter.Deserialize(String inputString) +221
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.Util.DeserializeWithAssert(IStateFormatter formatter, String serializedState) +0
System.Web.UI.HiddenFieldPageStatePersister.Load() +180
System.Web.UI.Page.LoadPageStateFromPersistenceMedium() +105
System.Web.UI.Page.LoadAllState() +35
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +7901
System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +217
System.Web.UI.Page.ProcessRequest() +11
System.Web.UI.Page.ProcessRequest(HttpContext context) +56
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +152
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +64

Check this out  Check this out

05-Aug-05 01:28 PM
Basically Viewstate is by default checked every time that the page is posted back to the server to ensure that it was not tampered. This is the "Machine Authentication Check". 
Now, the way this is done is that your ViewState is hahsed based on akey generated on  the web server. Now in a web farm scenario, you other server is not going to be aware of this key and hence when trying to decode it...thinks the Viewstate is Invalid. The way to go about this is to hard-code the ValidationKey in the machine.config.

Here are some links on how to do this.
http://www.eggheadcafe.com/articles/20030514.asp
http://channel9.msdn.com/wiki/default.aspx/Channel9.HowToConfigureTheMachineKeyInASPNET2

Another issue is with Server.Transfer and Server.Execute that cause Invalid Viewstate errors.
Here is an article on understanding that
http://www.eggheadcafe.com/articles/20030531.asp

thanks  thanks

05-Aug-05 02:00 PM
Is there something I can change in my code so that I don't get this error in case that my hosting company doesn't want to change anything?

I would not recommend bypassing the MAC  I would not recommend bypassing the MAC

05-Aug-05 02:06 PM
check. Although yes you can set EnableViewStateMAC to false in your page directive or machine.config that will make this error go away.
more strange behavior  more strange behavior
05-Aug-05 02:13 PM
If I use FireFox, I don't get the error.   But it makes me login at strange times.  Only getting the error on IE.  Is this normal with the error I have received?
This is not a client side issue  This is not a client side issue
05-Aug-05 02:24 PM
Could you answer some questions for me

1. Is you application on a web farm?
2. Do you use Server.Transfer on this page with the second attribute set to true?


The frequency of the issues suggest 1) cos sometimes your page behaves fine(it is posting back to the same web server) and sometimes errors out(posts to a different web server on your web farm).
Not sure  Not sure
05-Aug-05 02:31 PM
1.  My host has me on a shared server.  I will ask them if it is a web farm.  My host is ServerDivision if you have ever heard of them.
2.  I don't use Server.Transfer, at least I didn't code anything with it.
My WebApp is very simple and only 4 pages, plus the Login page.
I had a WebApp very similar to this in .NET 1.1 and I didn't have any of these problems.
Is this something that is new in ASP.NET 2.0?
Not on a web farm  Not on a web farm
06-Aug-05 11:02 AM
I talked to my hosting company and they said it is not a webfarm.  My webApp is on a server with other people's apps, shared hosting.
No sever transfer either  No sever transfer either
08-Aug-05 12:01 PM
I did a Find for all of my code and nowhere do I have server.transfer.  My Host doesn't know what to do either.  Any other ideas?
Check this link out  Check this link out
08-Aug-05 01:19 PM
http://weblogs.asp.net/owscott/archive/2004/11/02/251035.aspx
We have already talked about 1,3..but you may want to look at 2,4
Create New Account
help
Visual Studio .net .NET Framework Hi NG, ich habe vor längerer Zeit mit Visual Studio .Net 2003 gearbeitet und überlege momentan auf einen neueren Stand upzudaten. Ein Visual Studio .Net 2008 scheint es nicht zu geben. Habe zumindest mit googeln nichts gefunden. Was
Wise for Visual Studio.NET Wise for Visual Studio.NET By Peter A. Bromberg, Ph.D. To "Print This Page" Link Peter Bromberg Wise for Visual Studio .NET is a total and complete installation development system for creating and editing Windows® Installer
Visual Studio versioning . . . . how to tell? .NET Framework To my knowledge, Visual studio 6 was released in 1998, then Visual Studio .NET 2002 is VS 7, then Visual Studio .NET 2003 is VS 7.1, then Visual
visual studio.net 2003 and Access 2007 database .NET Framework Hi I am currently using Visual Studio.Net 2003 running on Windows Server 2000 operating system. I have used Visual Studio.net 2003 connecting to Access 2002 databases in the pass with great success. Now
Is Visual Studio self-hosting ? .NET Framework Does Microsoft use Visual Studio IDE, Visual Studio Debugger, Visual Studio Linker and Visual Studio compiler for developing Visual Studio ? Or is Visual Studio not