Those pesky query string parameters should better stay put...
-
One of my duties was to finish and maintain an application developed around 80% by somebody else. One of the pearls encountered in the code is this:
//if-else put here. Sometimes Querystring[2] is needed.
//other times it is QueryString[0]. Not sure why...
string id;
if (Request.QueryString.Count == 1) {
//id = Request.QueryString[0];
id = Request.QueryString[1];
} else {
id = Request.QueryString[2];
}
-
@rslite said:
One of my duties was to finish and maintain an application developed around 80% by somebody else. One of the pearls encountered in the code is this:
//if-else put here. Sometimes Querystring[2] is needed.
//other times it is QueryString[0]. Not sure why...
string id;
if (Request.QueryString.Count == 1) {
//id = Request.QueryString[0];
id = Request.QueryString[1];
} else {
id = Request.QueryString[2];
}Why can't those lazy web developers put their query parameters in the exact same order every time?!
-
@rslite said:
One of my duties was to finish and maintain an application developed around 80% by somebody else. One of the pearls encountered in the code is this:
//if-else put here. Sometimes Querystring[2] is needed.
//other times it is QueryString[0]. Not sure why...
string id;
if (Request.QueryString.Count == 1) {
//id = Request.QueryString[0];
id = Request.QueryString[1];
} else {
id = Request.QueryString[2];
}
I especially like how he never used QueryString[0], despite what the comment says. :D
-
Request.QueryString[ "paramName" ] was just too complicated.
-
@rslite said:
One of my duties was to finish and maintain an application developed around 80% by somebody else. One of the pearls encountered in the code is this:
//if-else put here. Sometimes Querystring[2] is needed.
//other times it is QueryString[0]. Not sure why...
string id;
if (Request.QueryString.Count == 1) {
//id = Request.QueryString[0];
id = Request.QueryString[1];
} else {
id = Request.QueryString[2];
}Um does .Count return 0 if there is 1 object? (thats another WTF)
Notice that [1] is used if there is 1 result ([0] should be used) and [2] is used if it is not == 1... what if its == 0? Man too much logic, i think ill just turn on the stove and choose the id that my teapot whistles out!
-
@dlikhten said:
@rslite said:
One of my duties was to finish and maintain an application developed around 80% by somebody else. One of the pearls encountered in the code is this:
//if-else put here. Sometimes Querystring[2] is needed.
//other times it is QueryString[0]. Not sure why...
string id;
if (Request.QueryString.Count == 1) {
//id = Request.QueryString[0];
id = Request.QueryString[1];
} else {
id = Request.QueryString[2];
}Um does .Count return 0 if there is 1 object? (thats another WTF)
Notice that [1] is used if there is 1 result ([0] should be used) and [2] is used if it is not == 1... what if its == 0? Man too much logic, i think ill just turn on the stove and choose the id that my teapot whistles out!
This thing is a great example of a bad understanding of both binary logic and causation vs. correlation.
-
Um, whatever that means. Everyone missed the obvious solution:
id = Request.QueryString[random.next(0,3)];
</sarcasm>