Web Applications

Are You Getting ViewState Errors like: "The viewstate is invalid for this page and might be corrupted."

If you’re seeing viewstate errors like “The viewstate is invalid for this page and might be corrupted” here’s the dealio.  For security ASP.NET encrypts the viewstate using an Autogenerated Key that is generated when your application pool (or worker process) is started. At AppliedI.net (and many hosts today) each website is placed in a unique application pool so your site is isolated from the other sites on the server. If your application pool recycles for whatever reason, the viewstate key will change and when you go to post back to your application is may fail with the gloriously informative error of:

“The viewstate is invalid for this page and might be corrupted”.

What’s causing the application pool to do this?

Your application pool is recycling due most likely to a couple things:

  1. you edited your web.config and that caused the change (not likely)
  2. IIS was reset on the server and that caused the change (less likely)
  3. Your application errored out causing the application pool to recycle (possible)
  4. Your application pool reached a memory limit and was forced to recycle (I put my money on the #4 horse to win! this is probably it)

All hosts today that use dedicated application pools, isolated application pools or “website sandboxing” whatever they may called also set a memory limit on the application pool in shared hosting, some set it more aggressively than others.  The advanced web applications of today are using more and more resources as they are more and more complex, it’s not uncommon to find a web application using anywhere from 150-350MB of memory today, although the average is still just in the range of 80-120MB. 

 

The good news is you have options on how to get around this. 

  1. You can upgrade your shared hosting account to an account that has a higher memory limit. At appliedi.net we offer 4 different shared hosting accounts each with separate memory limits.
  2. You can upgrade to a VPS hosting account or dedicated hosting account and set an even higher memory limit.
  3. You can completely disable the viewstatemac by adding “enableViewStateMac=”false” in your web.config. This would be a bad thing though and you can google viewstate injection for why this is bad.
  4. You can generate a predefined key and stop using the default autogenerated key method.

#4 is probably the route you’ll want to go. My recommendation is to go with #1 first and not just because I work for a hosting company and want to see you spend more money per month. I recommend you upgrade your hosting account to an account that has a reasonable memory limit for your application because every time that application pool recycles your site is going to be slow as it recompiles and initializes the application.  You also just lost your session state information so if you’re an ecommerce site and your client was in the middle of a checkout, they probably just lost their cart contents and have to start over.

Creating a predefined viewstatemac key

The guys over at www.aspnetresources.com have a keycreator tool that makes generating your own predefined viewstatemac key effortless. To do this you’d do the following

  1. visit: http://www.aspnetresources.com/tools/keycreator.aspx and use it to build a key
  2. Copy this key into your applications web.config file between <system.web> and </system.web>
  3. Save your web.config file and test your application to make sure it still works. If for some reason it doesn’t work, you can delete the changes and revert back.

Where to learn more

There’s always google. But Microsoft has a pretty extensive article in their KB at: http://support.microsoft.com/default.aspx?scid=kb;EN-US;829743 that will also help. If this sounds like something that’s happening to you at AppliedI.net on your ASP.NET hosting account please contact our support team and they’ll be happy to help you troubleshoot the issue.

How Microsoft UK got hacked and how you can learn from their mistakes

I subscribe to windowsecurity.com‘s newsletter which is actually a pretty good read. Today’s newsletter has an article about the Microsoft UK Events Website getting defaced and goes into great detail to show just how the site was compromised.

In a nutshell, they used SQL Injection and the fact that the web.config was configured to display errors instead of displaying a custom error page.

I highly recommend any developer or website owner to review the article at:

http://www.windowsecurity.com/articles/Microsoft-UK-Events-Website-Hacked.html

so that they can avoid falling prey to these same tactics. 

As a host, I can firmly say the #1 issue we see today with sites getting defaced is a weak password (using password, your username, your simple passwords simply aren’t secure) and the #2 issue is SQL Injection. Not many website owners (and unfortunately web developers) are familiar with SQL Injection and assume that their web app is inherently safe, this is a classic ASS-U-ME assumption. WindowsSecurity.com recommends that you use a commercial product from Acunetix to scan the security of your site. But other resources are:

  • ScanAlert’s (or any other reputable scanning company’s) PCI compliance scanning service: http://www.appliedi.net/scanalert-pcicompliance/ which is offered free for the first year for AppliedI.net hosted websites.
  • Nessus is a freely available scanning solution you can use as well (and the same tool many commercial security scanning providers use)
  • xfocus.org also has a scanning tool called x-scan that I like to use as well. It uses nessus rules but is created by a Chinese company so there’s not really any documentation on it.

This is by no means the end all article on web site security but if you read the windowsecurity.com article I think you’ll be more aware of the techniques being used by hackers today and if you sign up for one of the commercial services and also experiment with a few of the free tools available today you’ll be a little more aware of just what’s out there.

Oh and one word of advice on using security scanners, most hosts today employ IPS (intrusion protection servers) or some other network security devices so don’t be surprised if you attempt to scan your live website it becomes unavailable.  That could mean one of two things happened, one you crashed your website and have a serious issue or two, the host’s IPS or other network security saw your scans as an attack and has disabled your access to their network.  It’s a good idea to scan your application locally of course and should you need to do a remote scan let your host know before hand.

Free Blogs courtesy of webmastersdepot.com

My friends at webmastersdepot.com have been awesome. I’ve been helping them out with their VPS and the configuration of their applications and recently helped them setup wordpress mu.  WordPress MU is a blogging application built around wordpress (greatest blogging app available) that allows you to create a blogger.com, livespaces.com, wordpress.com (in fact it powers wordpress.com) type system. 

So the guys at webmastersdepot have now started offering free blog hosting! Say what? a webhost recommending someone else’s free hosting? Well, we believe it’s a good thing. Why? you’ll get a taste of wordpress and before long you’ll want to move to a full hosting account. Webmastersdepot.com will get affiliate credits for referring you and we’ll gain you as a hosting customer. It’s a win-win.

Anyway, head over to http://webmastersdepot.com/blogs/ and signup for your free blog today.