Invalid viewState

P

Pei Lu

dear all:

My logs are full of exceptions like this:


TYPE: HttpException

MESSAGE: Invalid viewState



System.Web.UI.Page.DecryptStringWithIV(String s, IVType ivType)

ÔÚ System.Web.UI.Page.DecryptString(String s)

ÔÚ
System.Web.Handlers.ScriptResourceHandler.DecryptParameter(NameValueCollection
queryString)

ÔÚ
System.Web.Handlers.ScriptResourceHandler.ProcessRequestInternal(HttpResponse
response, NameValueCollection queryString, VirtualFileReader fileReader)

ÔÚ System.Web.Handlers.ScriptResourceHandler.ProcessRequest(HttpContext
context)

ÔÚ
System.Web.Handlers.ScriptResourceHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext
context)

ÔÚ
System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()

ÔÚ System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&
completedSynchronously)



I'd like to put an end to this if possible... ideas?
 
G

Gregory A. Beamer

dear all:

My logs are full of exceptions like this:


TYPE: HttpException

MESSAGE: Invalid viewState



System.Web.UI.Page.DecryptStringWithIV(String s, IVType ivType)

ÔÚ System.Web.UI.Page.DecryptString(String s)

ÔÚ
System.Web.Handlers.ScriptResourceHandler.DecryptParameter (NameValueCol
lection queryString)

ÔÚ
System.Web.Handlers.ScriptResourceHandler.ProcessRequestInternal (HttpRe
sponse response, NameValueCollection queryString, VirtualFileReader
fileReader)

ÔÚ
System.Web.Handlers.ScriptResourceHandler.ProcessRequest (HttpContext
context)

ÔÚ
System.Web.Handlers.ScriptResourceHandler.System.Web.IHttpHandler.Proc e
ssRequest(HttpContext context)

ÔÚ
System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApp l
ication.IExecutionStep.Execute()

ÔÚ System.Web.HttpApplication.ExecuteStep(IExecutionStep step,
Boolean&
completedSynchronously)



I'd like to put an end to this if possible... ideas?

There are quite a few things that can cause this. One thing I would look
at is whether or not the application is recycling. You can check the
event log for this. If so, your viewstate issue may actually indicate a
completely different, and perhaps bigger, problem.

Another possibility is you are on a web farm with different machine
keys. On machine 2, it cannot decode the viewstate and is throwing an
error.

There is a hotfix that might help you better determine the problem if
this is a ASP.NET 1.0 app (there is a link for a 1.0 version of the
hotfix): http://support.microsoft.com/kb/831150

Another possibility is dynamically loading controls without making the
controls viewstate aware.

EnableViewStateMac settings can also affect whether the error is thrown,
but I would be careful simply setting to false to avoid exceptions, as
you may just be masking the problem.

Throwing objects that are not serializable into viewstate can cause the
issue.

One other possible fix is setting the machine keys manually for the
application.

In other words, without seeing code, or looking at your app, I can only
shoot fish in the dark. Hopefully one of the above helps you.

Peace and Grace,
 
A

Allen Chen [MSFT]

Hi Pei,
I'd like to put an end to this if possible... ideas?

As Gregory said, this issue is generally caused by machinekey related
issue. See following source code:

internal static string DecryptStringWithIV(string s, IVType ivType)
{
if (s == null)
{
return null;
}
byte[] buf = HttpServerUtility.UrlTokenDecode(s);
if (buf != null) //normally buf is not null at this point so it will
execute the inner code:
{
buf = MachineKeySection.EncryptOrDecryptData(false, buf, null, 0,
buf.Length, ivType); //in your case it returns null here
}
if (buf == null)
{
throw new
HttpException(SR.GetString("ViewState_InvalidViewState"));//throw exception
}
return Encoding.UTF8.GetString(buf);
}

If it still keeps throwing this exception, please let me know details about
your scenario:

"Are you hosting your app in a Web Farm?
"Have you specified machinekey in web.config? What's your setting?
"What's the result if you set long recycle period?

Reference you may need:

How To: Configure MachineKey in ASP.NET 2.0
http://msdn.microsoft.com/en-us/library/ms998288.aspx

Regards,
Allen Chen
Microsoft Online Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the

support we provide to you. Please feel free to let my manager know what you
think of the level of service provided.

You can send feedback directly to my manager at: (e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-

us/subscriptions/aa948868.aspx#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community

or a Microsoft Support Engineer within 2 business day is acceptable. Please
note that each follow up response may

take approximately 2 business days as the support professional working with
you may need further investigation to

reach the most efficient resolution. The offering is not appropriate for
situations that require urgent, real-time

or phone-based interactions. Issues of this nature are best handled working
with a dedicated Microsoft Support

Engineer by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-

us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
A

Allen Chen [MSFT]

Hi Pei,
I'd like to put an end to this if possible... ideas?

Do you have any progress on this issue?

Regards,
Allen Chen
Microsoft Online Support
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top