I saw my friend doing some Web Development, and one of his code caught my attention is the Response.Redirect.
What is the use of Home?=, isn’t it the LogIn.aspx is the name of the page how come it’s still redirecting if it has Home?=. Can someone answer this question of mine please, and explain it very well.
String url = "LogIn.aspx?Home?=" + Username;
Response.Redirect(url);
Update
Working from all your comments, the answer is: The query string parameter name (key) is actually
"Home?", not just"Home". Details (including why the code generating that is technically incorrect) below.Because there’s no reason it shouldn’t redirect. Granted the URL is invalid (
?is a reserved character, it cannot appear unencoded in the query string, so the second?in the URL is incorrect), but browsers are pretty content to deal with invalid URLs.Separately, unless
Usernamehas already been URL-encoded, the URL could have other errors depending on the content ofUsername. (All query string parameters must be URL-encoded, in .Net you do that withHttpUtility.UrlEncode.)Re your comment:
It has no use, it’s an error.
He probably just meant(no, apparently not, see below after your next comment)…which would more correctly be:
(Technically, you have to URL-encode both the keys and values [both
"Home"andUsername], but the URL-encoded form of"Home"is"Home", so we can get away without making the call for the key. Not true if the key needs to have any of the URL reserved characters in it.)Re your further comment consisting entirely of this code:
Assuming the syntax error in the above is fixed (missing
]on line 3), it would appear that he’s actually using"Home?"as a key (parameter name). That means the redirect should be:…because the key has a reserved character in it (
?). Because that will be decoded for you on receipt, that should make the code above work.Note that most browsers will probably let you get away with the string as he specified it. It’s incorrect, but in a way browsers probably allow.