The HTML Print Value – The Daily WTF

Date:

Share:

Matt was handed a pile of VB .Net code, and told, “This is yours now. I’m sorry.”

As often happens, previous company leadership said, “Why should I pay top dollar for experienced software engineers when I can hire three kids out of college for the same price?” The experiment ended poorly, and the result was a pile of bad VB code, which Matt now owned.

Here’s a little taste:


Session["PrintValue"] = GenerateHTMLOfItem();
Response.Redirect("PrintItem.aspx", true);

The function name here is accurate. GenerateHTMLOfItem takes an item ID, generates the HTML output we want to use to render the item, and stores it in a session variable. It then forces the browser to redirect to a different page, where that HTML can then be output.

You may note, of course, that GenerateHTMLOfItem doesn’t actually take parameters. That’s because the item ID got stored in the session variable elsewhere.

Of course, it’s the redirect that gets all the attention here. This is a client side redirect, so we generate all the HTML, shove it into a session object, and then send a message to the web browser: “Go look over here”. The browser sends a fresh HTTP request for the new page, at which point we render it for them.

The Microsoft documentation also has this to add about the use of Response.Redirect(String, Boolean), as well:

Calling Redirect(String) is equivalent to calling Redirect(String, Boolean) with the second parameter set to true.
Redirect calls End which throws a ThreadAbortException exception upon completion. This exception has a detrimental effect on Web application performance. Therefore, we recommend that instead of this overload you use the HttpResponse.Redirect(String, Boolean) overload and pass false for the endResponse parameter, and then call the CompleteRequest method. For more information, see the End method.

I love it when I see the developers do a bonus wrong.

Matt had enough fires to put out that fixing this particular disaster wasn’t highest on his priority list. For the time being, he could only add this comment:



Session["PrintValue"] = GenerateHTMLOfItem();
Response.Redirect("PrintItem.aspx", true);

[Advertisement]
Keep all your packages and Docker containers in one place, scan for vulnerabilities, and control who can access different feeds. ProGet installs in minutes and has a powerful free version with a lot of great features that you can upgrade when ready.Learn more.

Source link

Subscribe to our magazine

━ more like this

Rundkappelenplatz in Nuremberg, Germany

Die Rundkapelle (“the round chapel”) is tucked away in Altenfurt, an unassuming little corner of Nuremberg. A meditative path, guided in part by a...

Let fires burn, with Selina Tobaccowala

CHERYL KELLOND: I’m driving this huge rig that’s like 35 feet long over highways and bumpy roads. HOFFMAN: That’s Cheryl Kellond, entrepreneur and amateur...

Office manager gets fired and replaced by new hire for 1/4 of their salary, learns his $2,500 bonus is conditional on training his replacement:...

Most employees would take the money and begrudgingly follow orders, but several members of this online community were correct in suggesting that perhaps there...

Red-Dress Halloween Costume Ideas | PS Fashion

While each product featured is independently selected by our editors, we may include paid promotion. If you buy something through our links, we may...

The BEST Nordstrom Anniversary Sale 2019 Picks!

You guys know I've been a huge fan of the Nordstrom Anniversary Sale for the last 6 or so years so I have a...