I fixed a tricky bug yesterday on one of our sites that runs ASP.NET. Like all good webmasters, anytime a 500 error occurs on the site, an email is sent to me that contains all the juicy details: the URL the user was visiting, the date/time, what browser they were using, which server in the cluster it occured on, the stack trace, any form variables, the querystring, session variables, and cookies. This particular error would occur on any page with a form and the stack trace would look like this:
Exception of type System.Web.HttpUnhandledException was thrown.
source = System.Web
target site = Boolean HandleError(System.Exception)
stack trace = at System.Web.UI.Page.HandleError(Exception e) at
System.Web.UI.Page.ProcessRequestMain() at
System.Web.UI.Page.ProcessRequest() at System.Web.UI.Page.ProcessRequest(HttpContext context) at System.Web.CallHandlerExecutionStep.System.Web.HttpApplication+IExecutio
nStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep
step, Boolean& completedSynchronously)
which isn’t very helpful at all. So my first problem was that I wasn’t getting enough information; I couldn’t tell what the problem really was. The HttpModule that I wrote that listens for Application_Error events was retrieving the exception using this code:
HttpApplication application = (HttpApplication)source;
Exception error = application.Server.GetLastError();
which technically does retrieve the error that caused the event, but I was missing one key step: the last line should have read:
Exception error = application.Server.GetLastError().InnerException;
and once I fixed that, I magically started receiving a much richer error description:
System.Web.HttpException: The viewstate is invalid for this page and might be corrupted. at System.Web.UI.Page.LoadPageStateFromPersistenceMedium() at System.Web.UI.Page.LoadPageViewState() at System.Web.UI.Page.ProcessRequestMain()
That description leads to a couple different knowledge base articles on support.microsoft.com; Q323744 and Q312906 were the ones that fixed the problem I was experiencing. Turns out that when you a) run an ASP.NET application in a cluster (in my case it’s an ASP.NET application load balanced behind with an F5), b) don’t use sticky sessions, and c) utilize view state, you must setup your web servers to use the exact same machine key, which is a setting in machine.config. Microsoft supplies a C# script that will generate the appropriate machineKey element for you machine.config in Q312906.
What’s Going On Here?
My name is Aaron Johnson and I created this blog both for me (mostly) and sometimes you. I've been saving mydeliciouspinboard.in links here and blogging since 2002. During the week (and at night and some weekends and well.. most of the time), I work in engineering at Jive Software. When I'm not working, I'm hanging out with my amazing wife, ourdinosaurStar Wars loving son and four chickens in the burbs outside of Portland, Oregon.See Also
Monthly Archives
- May 2013 (3)
- April 2013 (4)
- March 2013 (3)
- February 2013 (5)
- January 2013 (7)
- December 2012 (1)
- November 2012 (4)
- October 2012 (5)
- September 2012 (3)
- August 2012 (3)
- July 2012 (7)
- June 2012 (5)
- May 2012 (3)
- April 2012 (5)
- March 2012 (5)
- February 2012 (9)
- January 2012 (9)
- December 2011 (10)
- November 2011 (6)
- October 2011 (6)
- September 2011 (5)
- August 2011 (5)
- July 2011 (8)
- June 2011 (13)
- May 2011 (3)
- April 2011 (10)
- March 2011 (6)
- February 2011 (2)
- January 2011 (4)
- December 2010 (8)
- November 2010 (12)
- October 2010 (9)
- September 2010 (6)
- August 2010 (4)
- July 2010 (8)
- June 2010 (9)
- May 2010 (4)
- April 2010 (9)
- March 2010 (6)
- February 2010 (9)
- January 2010 (10)
- December 2009 (10)
- November 2009 (10)
- October 2009 (6)
- September 2009 (10)
- August 2009 (13)
- July 2009 (12)
- June 2009 (11)
- May 2009 (8)
- April 2009 (4)
- March 2009 (7)
- February 2009 (2)
- January 2009 (3)
- December 2008 (4)
- November 2008 (7)
- October 2008 (10)
- September 2008 (6)
- August 2008 (7)
- July 2008 (9)
- June 2008 (15)
- May 2008 (9)
- April 2008 (10)
- March 2008 (8)
- February 2008 (6)
- January 2008 (15)
- December 2007 (10)
- November 2007 (9)
- October 2007 (6)
- September 2007 (9)
- August 2007 (12)
- July 2007 (9)
- June 2007 (6)
- May 2007 (8)
- April 2007 (10)
- March 2007 (14)
- February 2007 (12)
- January 2007 (17)
- December 2006 (11)
- November 2006 (11)
- October 2006 (8)
- September 2006 (11)
- August 2006 (14)
- July 2006 (11)
- June 2006 (13)
- May 2006 (11)
- April 2006 (8)
- March 2006 (5)
- February 2006 (7)
- January 2006 (8)
- December 2005 (6)
- November 2005 (6)
- October 2005 (9)
- September 2005 (3)
- August 2005 (11)
- July 2005 (12)
- June 2005 (11)
- May 2005 (4)
- April 2005 (5)
- March 2005 (8)
- February 2005 (5)
- January 2005 (3)
- December 2004 (6)
- November 2004 (7)
- October 2004 (4)
- September 2004 (9)
- August 2004 (5)
- July 2004 (10)
- June 2004 (12)
- May 2004 (4)
- April 2004 (13)
- March 2004 (10)
- February 2004 (9)
- January 2004 (13)
- December 2003 (8)
- November 2003 (9)
- October 2003 (17)
- September 2003 (28)
- August 2003 (21)
- July 2003 (24)
- June 2003 (31)
- May 2003 (43)
- April 2003 (30)
- March 2003 (48)
- February 2003 (45)
- January 2003 (43)
- December 2002 (28)
- November 2002 (30)
- October 2002 (34)
- September 2002 (41)
- August 2002 (35)
- July 2002 (20)
- June 2002 (1)
Aaron,
We have the same problem. We have tried all the solutions listed under MS Support articles (and still working with MS to figure out the issue). We have F5 (big-ip) load balancer with Sticky sessions turned on. The issue is, Authentication is lost & user is kicked out to login page intermittently. So far, we have tried:
1. Time-out set to higher rate (and turn Sliding expiration on).
2. Path in Web.config for the Auth cookie is “/”
3. Session expires after 29 hours.
4. Captures Viewstate Log, Forms Auth log – found the auth ticket is lost intermittently. So now we are trying to get the NetMon trace to see if the network is causing some packets to be lost (per MS suggestion!)
I guess if you have any sugesstions please email me -2005jay@gmail.com
Thanks a ton!
Hi all! Mi name is Michael. I’m from Costa Rica and I’m a .net programmer. But I need some help.
I’ve got an error working with F5 Big Ip virtual farm:
This is my scenario.
1-I’ve developed a .net 2.0 remoting application.
2-I’m using four Windows Services to host my remoting objects.
3-I’m using TCP Channel and SAO activation.
4-This is the Windows Services .app config
5- This is the Client Activation:
CType(Activator.GetObject(GetType(Interfaces.Operaciones.ICierresDiarios), Aplicacion.TraerURLOperaciones & “/CierresDiarios”), Interfaces.Operaciones.ICierresDiarios)
6-I have a Middleware farm (F5 BIGIP) address (192.168.162.162). This farm has two nodes (192.168.162.50, 192.168.162.51).This nodes has the same hardware and software specification. Both of them have installed my Windows Services.
7-When I try to connect thought out farm (192.168.162.162) I get this error “An active connection was forcibly closed by remote host†or even:
System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond Server stack trace: at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) at System.Net.Sockets.Socket.Connect(EndPoint remoteEP) at System.Runtime.Remoting.Channels.RemoteConnection.CreateNewSocket(EndPoint ipEndPoint) at System.Runtime.Remoting.Channels.RemoteConnection.CreateNewSocket() at System.Runtime.Remoting.Channels.SocketCache.GetSocket(String machinePortAndSid, Boolean openNew) at System.Runtime.Remoting.Channels.Tcp.TcpClientTransportSink.SendRequestWithRetry(IMessage msg, ITransportHeaders requestHeaders, Stream requestStream) at System.Runtime.Remoting.Channels.Tcp.TcpClientTransportSink.ProcessMessage(IMessage msg, ITransportHeaders requestHeaders, Stream requestStream, ITransportHeaders& responseHeaders, Stream& responseStream) at System.Runtime.Remoting.Channels.BinaryClientFormatterSink.SyncProcessMessage(IMessage msg) Exception rethrown at [0]: at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) at
8 I try to connect to a single node 192.168.162.50 OR 192.168.162.51 individually and I don’t get any error.
I’ve noticed that the network manager created just a Http Profile on F5, is this right?
Thanks for your help!.
Hi all,
My site having smile problem as below. Could somebody help me to resolve this problem?
Server Error in ‘/GenericWebbookCC’ Application.
——————————————————————————–
The state information is invalid for this page and might be corrupted.
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: The state information is invalid for this page and might be corrupted.
Source Error:
[No relevant source lines]
Source File: c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\genericwebbookcc\88714d05\b5a2d222\App_Web_default.aspx.cdcab7d2.p16vjrnz.0.cs Line: 0
Stack Trace:
[ViewStateException: Invalid viewstate.
Client IP: 127.0.0.1
Port:
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)
ViewState: /wEWdQKV0KTHDwLzsONuAoGT+bULAqmVsPoIAsDvr/0DAt/vr/0DAtCAhZMPAoTm9BgCg+aYGwKD5pQbAoPmkBsCguaUGwKIifL2DALf8NKwDALA8NKwDALPn/heAsW8mNYBAt6z5+sLAsGz5+sLAs7czYUHAu/shNkCAtDfxO4EAvaD4ugCAqns3JgOAqns2JgOAqnsgJgOAqns4JkOAqjs/JgOAqvsxJgOAqvszJgOAqvsuJgOAqrs/JgOAqrs9JgOAqzs2JgOAq/sxJgOAp7spJgOApHsxJgOApHs+JgOApHs2JgOApHs0JgOApPsvJgOApPs5JkOApLsxJgOApXsxJgOApXs+JgOApXs9JgOApXspJgOApXs0JgOApXszJgOApXsvJgOApXsuJgOApTs/JgOApTs+JgOApTs9JgOApTsqJgOApTsoJgOApTs1JgOApTssJgOApTs5JkOApfsqJgOApfs3JgOApfs0JgOApfsgJgOAobsxJgOApjspJgOApvs/JgOApvs+JgOAprs0JgOAprs6JkOAp3suJgOApzsxJgOApzsuJgOAp/sxJgOAp/spJgOAp/ssJgOAp/s5JkOAvy/+ZAHAunar+MKApz+8rsJApnJ7xEC8LyVdALg44jgAgL/44jgAgLvjKKODgLjluj/AwLgluj/AwLlu/vwAgLtqKfMAwLqnq4tAt7L6ogFAuur+sUGAtKor8AFAoz885MDAvup2qEJAvSjz7ACAvrSnI4HAvrDt60LAsCbxtIIArW25scDArK2isQDArK2hsQDArK2gsQDArO2hsQDArnZ4KkPAqq...]
[HttpException (0x80004005): The state information is invalid for this page and might be corrupted.]
System.Web.UI.ViewStateException.ThrowError(Exception inner, String persistedState, String errorPageMessage, Boolean macValidationError) +170
System.Web.UI.ViewStateException.ThrowViewStateError(Exception inner, String persistedState) +37
System.Web.UI.ClientScriptManager.EnsureEventValidationFieldLoaded() +371
System.Web.UI.ClientScriptManager.ValidateEvent(String uniqueId, String argument) +202
System.Web.UI.Control.ValidateEvent(String uniqueID, String eventArgument) +83
System.Web.UI.WebControls.RadioButtonList.LoadPostData(String postDataKey, NameValueCollection postCollection) +242
System.Web.UI.WebControls.RadioButtonList.System.Web.UI.IPostBackDataHandler.LoadPostData(String postDataKey, NameValueCollection postCollection) +36
System.Web.UI.Page.ProcessPostData(NameValueCollection postData, Boolean fBeforeLoad) +478
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5899
System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +281
System.Web.UI.Page.ProcessRequest() +112
System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +37
System.Web.UI.Page.ProcessRequest(HttpContext context) +135
ASP.default_aspx.ProcessRequest(HttpContext context) in c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\genericwebbookcc\88714d05\b5a2d222\App_Web_default.aspx.cdcab7d2.p16vjrnz.0.cs:0
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +713
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +117
——————————————————————————–
Version Information: Microsoft .NET Framework Version:2.0.50727.1433; ASP.NET Version:2.0.50727.1433
Hey thanks a million, was having a nightmare with this as all I was getting was UnhandledHttpException but your fix did it for me, one thing I would suggest tho is that sometimes the InnerException is null so test for that first otherwise your error-handling code will itself cause an error, also the innerException can have an innerException so you might want to try looping through until no more innerexceptions are found