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.