Article H23G CodeSOD: Count On It

CodeSOD: Count On It

by
Jane Bailey
from The Daily WTF on (#H23G)

320px-Duct-tape_Moving_Van.jpg

If there's one thing more exhausting and ridiculously over-complicated than moving house, it's moving legacy apps. Something as simple as a migration to another, identically configured (in theory) server can cause unexplained breakages and weird glitches in bits of the code no current staff member has ever touched.

Mikail's company knew better than to try to extract this particular app and repot it in another server. After all, most of the core functionality was written by interns several years back, and since it wasn't in source control at the time, nobody had been willing to touch it. But with a major merger came a domain name change, leading to a slew of unexpected errors in production (Test environment? What test environment?).

The following was designed to obtain a number from the query string so it could figure out what product to display. Most seasoned .NET professionals would go right for Request.QueryString["number"];, but not this special snowflake:

 protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { //... string strUrl = HttpContext.Current.Request.Url.AbsoluteUri; string strNumber = ""; if (strUrl.Contains("?") == true) { strNumber = strUrl.Substring(58, strUrl.Length - 58); } //... } }

She counted the number of characters in the base URL before the query parameter she wanted, and took a substring from the URL. While that worked for a time, the new domain was longer, leading to errors when bits of the path were converted to an Integer. At least it was easy to find the error. One down, only a dozen left.

inedo50.png[Advertisement] BuildMaster is more than just an automation tool: it brings together the people, process, and practices that allow teams to deliver software rapidly, reliably, and responsibly. And it's incredibly easy to get started; download now and use the built-in tutorials and wizards to get your builds and/or deploys automated! TheDailyWtf?d=yIl2AUoC8zAmJxIcKyFnxc
External Content
Source RSS or Atom Feed
Feed Location http://syndication.thedailywtf.com/TheDailyWtf
Feed Title The Daily WTF
Feed Link http://thedailywtf.com/
Reply 0 comments