trap and ignore invalid viewstate

D

Deepika

Hello,
I am trying to trap the invalid_viewstate error in my application so
that an error email does not get sent.

In my global.asax under Application_Error:

Exception ex=Server.GetLastError();

if(ex.ToString().IndexOf("Invalid_Viewstate_Client_Disconnected") ==
-1)
{
send error email }
else
{
don't send error email }


I have tried using server.getlasterror().getbaseexception() and
ex.message just to make sure that I was not searching in incomplete
error message
However I still get error email for invalid_viewstate error.

Please can somebody point why indexof is not able to find the string
with in the error message?
Thanks,
Deepika
 
T

Tor Bådshaug

Hi,

how do you know that you actually get the invalid_viewstate_* exception?
Your answer should be straightforward if you track down the details of the
exception you would like your test to catch.
In general, it is not advisable to create conditional logic that is based on
....ToString().IndexOf("......") like this. Such a test is fragile (such
fragile conditionals may be ticking bombs in your application that may
trigger for instance when upgrading to a future version of the framework.
Exception handling should, whenever possible, be performed based on the
exception's type.

Tor Bådshaug
tor.badshaug [//at\\] bekk.no.
 

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,989
Messages
2,570,207
Members
46,782
Latest member
ThomasGex

Latest Threads

Top