Query String Returning Different Values to that of the actual in the url - asp.net

http://localhost:1079/BattleSimulator.aspx?userID=Unregistered_User&Troops=1111%1111%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0!1111%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0&Research=10%10%10%10%10%10%0!10%10%10%10%10%10%0&Sanctuary=0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0!0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0&Inventory=False%False%False%False%False%False!False%False%False%False%False%False&other=5!0&RNG=0&Dragons=-1%-1%-1%-1!-1%-1%-1%-1&BattleArts=0%0%0!0%0%0&Kaizer=2310000%1510000%0%15867000%910000%875!5011000%2810000%3158%182972948%2810000%803
^ this is the original Query Passed onto server,
But this is parsed on a very different way on the server
Ex:
http://prntscr.com/3h90fs
http://prntscr.com/3h90o2
the string returned from
Extention.QueryString("Troops")
is "111111%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0!1111%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0%0"
Why is this happening ? is it a bug ?

There are many chars that are reserved and can't be used in querystring. % is one of those.
You have to Encode a string to be shure that it will be properly decoded to the same string in the server.
In C# this can be done this way:
HttpContext.Current.Server.UrlEncode(destinationURL);

Why is this happening ?
Because added any(some) spaces(White Character ) between your values.
is it a bug ?
Nope. It's not a bug .
Solution.
You need use Trim() or remove Empty values by using Replace(" ","") in your query string values before send query string
See this links
Get Query String value containing spaces
Passing in a querystring with a space?
http://blogfornet.com/tag/how-to-use-space-in-url-query-string/
Request.QueryString giving me space instead of + sign

Related

Passing Empty string parameter in URL

I want to pass an empty string parameter in a url. I don't know how to do it.
I am passing these parameters in the url for a grid. In the database if I using Race=''. I get the respective records. I need to pass this in the url
test.aspx?race=""
The url would look like this:
text.aspx?race=
or
text.aspx?race=&otherParam=value&etc=otherValue
Then you would have code to handle race being empty:
if(string.IsNullOrEmpty(Request.QueryString["race"]))
// handle the empty race differently
You can pass an empty string in url like this
test.aspx?race=%02%03
%02 - start of text ASCII Character
%03 - end of text ASCII Character
In this page you can find other characters too.
Dim race As String
race = ""
Response.Redirect("page.aspx?race=" & race)
Is this what you want??

how to decode QUrlnfo.name()?

I received the following QUrlInfo string from QFtp::listInfo(QUrlInfo) and the correct URL fragment is actually set to ©®§µ here in a test.
But QUrlInfo.name() returns a String containing ©®§µ. I realize I must encode it somehow, but how do I do that?
This should work:
QString::fromUtf8(info.name().toAscii());

"&" inside QueryString value

I'm using QueryStrings for users to auto-select values from a drop down list. Some of the values in this drop down list contain "&" in them.
E.g. "Acquisitions & Development"
When the user passes through a value with an "&", the string value gets cut off before the second half.
string functionalDepartment = Request.QueryString["FunctionalDepartment"];
//returns "Acquisitions "
Is there a way that I can include the second half of the value when getting the value from the QueryString?
The & character needs to be URL encoded because & is used to divide the query string into name=value pairs. When creating the URL, use:
HttpUtility.UrlEncode(url);
Before passing it to query string just replace:
.Replace("&","%26");
or use Server.URLEncode()
You could user System.Web.HttpUtility.UrlEncode while setting the values for the drop down.
This will ensure that & will not break the values.
Use HttpServerUtility.UrlEncode:
URL encoding ensures that all browsers will correctly transmit text in URL strings. Characters such as a ampersand (&) might be truncated or corrupted by some browsers.
More Details see this Query strings with special characters
I also refer that
Server.UrlEncode("url") will solve ur issue.
Example:
MyURL = "http://www.ursite.com/urpage.aspx?ReqStr=" + Server.UrlEncode("ASP.NET Examples");

asp.Net + encrypted QueryString requested not reading '+' sign

I have an encrypted query string passed from another page, it reads something like "/se73j+sef" but after receiving it, the '+' sign got omitted and became "/se73j sef". Is this normal? Please kindly advice. Thanks.
Is this normal?
Yes, perfectly normal. + is a special character in an url. It means space (0x20 ASCII character). If you want to represent the + sign you will have to url encode it:
/se73j%2Bsef
To url encode a string in .NET you could use the UrlEncode method. Or depending on how you are building the url there are certainly better ways.

Issue with sending Base64 encoded query string in aASP.Net

I am creating a web site in .Net 3.5 , I am converting the string into Base64String to send it through querystring. The Response.Redirect works fine for smaller string. But if the original string size is 1670, the response.redirect results in error "Page can not be found".
item is the string in below code snippet.
byte[] data = Encoding.Default.GetBytes(item);
return Convert.ToBase64String(data)
Can any one please help in resolving this?
A query string shouldn't be used for long values - while it depends on the browser and web server exactly what the maximum safe length is, it's certainly not safe above about 2000 characters, and I'd be wary about relying on it above 255. The solution is to use a POST request instead, or possibly to save the data on the server and pass a key to it in the query string.
There is a limit on characters sent as a query string - it varies from browser to browser:
http://support.microsoft.com/kb/q208427/
I'd save it to a DB and retrieve it on the other end with a key.

Resources