Crazy Hack of the Day

Today, with a suggestion from the USDA Breakmaster, I completed an amazing hack, that I'm really pretty proud of.  We're trying to move an application to the .NET 2.0 framework.  It was a nobrainer conversion, and it was all but deployed until we found a bug a boo in one of the pages that interfaces with another web application.  Invalid Cast Exception...blah blah blah.  The other application(ASP.NET 1.1) pops up a browser window pointing to a page in our site(now on the 2.0 runtime).  It does some stuff in our site, and when they are done the "OK" button gets pressed.  The "OK" button is on our site, posts back to our site, does some other stuff, sets some hidden variables in the codebehind, then writes out some javascript to run when the page loads that looks like this:

Document.forms[0].action = "http://someotherside.com/somepage.aspx";

The net effect is that our page posts to another site. Well, .NET 1.1 viewstate apparently does not like .NET 2.0 viewstate.  There are some workarounds that didn't work for us, or we weren't patient enough to figure out how to get them to work.  Either way, the hack we came up works, and it's just as bad as the problem it's solving.

The first take of this hack had me setting the __VIEWSTATE variable to an empty string.  That hack was NOT well received by the other application.  The Breakmaster suggested getting the viewstate from the 1.1 page first, then substituting that for the 2.0 viewstate.  It's a little confusing but it actually worked.  Right before we do the post to the other site, we request the page from the other site, parse out the __VIEWSTATE contents using nothing but string manipulation, then do something like this on the 2.0 site:

Document.getElementById('__VIEWSTATE').value = 'the viewstate we scraped from the 1.1 site';

Anyway, the entire solution is ridiculously stupid, and I successfully made it even more stupid, it was a good day...

 
Author: , 0000-00-00