Passing Empty string parameter in URL - asp.net

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??

Related

Query String Returning Different Values to that of the actual in the url

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

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");

I want to create an expression for querystrings, this stuff is hard!

I want to extract some keywords out of a query string for a search application in asp.net.
I decoded the url string first, so it's plain text
I have this to start with, but I want to add a keyword group
([\?\&])q=[^\&]+[\&]?
I get this ?q=harbour landing dental&
I'd like to trim off the stuff for pure words, but not sure if that's possible
I also have a long list of possible query string value fields that I want to check against
?q=
#q=
?qs=
&qs=
Why don't you just use the HttpRequest.QueryString collection?
If you have access to the HttpRequest you should just use the HttpRequest.QueryString property.
If you don't have access to that and only have the actual query string as a string you should just use the HttpUtil.ParseQueryString function to get the NameValueCollection.

How do I identify the referrer page in ASP.NET?

In VS2003, I am trying to find out the particular page where the request is coming from. I want to identify the exact aspx page name.
Is there a way to only get the page name or some how strip the page name?
Currently I am using the following instruction...
string referencepage = HttpContext.Current.Request.UrlReferrer.ToString();
and I get the following result...
"http://localhost/MyPage123.aspx?myval1=3333&myval2=4444;
I want to get the result back with out any query string parameters and be able to identify the page MyPage123.aspx accurately...
How do I do that??
Instead of calling .ToString on the Uri, use the AbsolutePath property instead:
string referencepage = HttpContext.Current.Request.UrlReferrer.AbsolutePath;
This should get you "/MyPage123.aspx" in your case.
Edit: Had LocalPath instead of AbsolutePath by mistake
Look at the Segments property of the URI class (which is what HttpContext.Current.Request.UrlReferrer returns).
Something like HttpContext.Current.Request.UrlReferrer.Segments[1] (changing the 1 indexer to get the correct segment you require).

Resources