HttpRequest.QueryString can be a pretty useful and powerful tool for a .NET web site. I hadn't used this property in almost a year and was recently reintroduced to it due to a request from a co-worker. I wrote an application [shortLink] last November ('05) that takes really long URLs and shortens them to something manageable, very similar to TinyURL. The reason I even did this was because I wanted this functionality on our corporate network and it didn't exist. That's the beauty of working at Microsoft...if something doesn't exist and you want to create it, then by all means...do it. Anyway, a co-worker emailed me yesterday and asked if there was a bookmarklet he could use that would take any page he was currently viewing and submit it to shortLink for conversion. I had wanted to do this, but hadn't gotten around to it yet. Backburner and all that. 
Admittedly, I had a brainfart at first and couldn't remember how the heck to do this. I remembered something about the ? after the .aspx denoting a string, but for the life of me I just couldn't pull the information out of the dark recesses of my brain. So I started searching online and after 30 minutes of fruitless searches [using "parsing a url in .net", "how to read the string after .aspx?", "what comes after a url formatted like .aspx?", etc.] I eventually landed here. Then my d'oh meter went off and I smacked myself upside the head, because it is so simple. 
Anyway, you probably made it here through some search query [better formatted than mine I hope] so let's get on with it. Here's a short description of the HttpRequest.QueryString collection and a quick tutorial how to use it to pass a string to an ASP.NET page and then manipulate it.
Here's a summary description from the sitepoint article:
In case you're not familiar with query strings, the basic idea is to tack on a set of variables to the end of the URL that appears in the browser's Address field. For example, if there were a page on your site with URL http://www.yoursite.com/welcome.asp, then you could send that page my first and last name by adding a query string to the address as follows:
http://www.yoursite.com/welcome.asp?firstname=Kevin&lastname=Yank
The portion of the URL thats in bold is the query string. A query string always begins with a question mark (?), which marks the end of the standard URL. The query string, which follows the question mark, is a series of one or more name/value pairs separated by ampersands (&). In this case, we have two such pairs. The variable name firstname is given a value of Kevin, and the variable name lastname is given a value of Yank.
These values are passed into the HttpRequest.QueryString collection and we can then access them with something as simple as: string firstName = Request.QuerySting["firstname"]. The string firstName then has the value of Kevin (assuming the example above). Like any NameValueCollection you, can also reference the the name-value pairs by the index number. In the above example, Request.QueryString[0] would give you the firstname value and Request.QueryString[1] would give you the lastname value.
It might be worth noting here that although the QueryString property is a member of the HttpRequest class, you access the QueryString collection by using the Request property of the Page class which gets the HttpRequest object for the requested page. Make sense? If not, don't worry too much about it...just know that you use Request.QueryString to access the name-value collection.
So what did I do in my implementation? Well, here's the code I slung together:
1: private void CheckQueryString()
2: {
3: if (!Request.QueryString.Count.Equals(0))
4: {
5: if (Request.QueryString.AllKeys[0].ToLower().Equals("linktoshorten"))
6: {
7: textBoxLongUrl.Text = Request.QueryString["linktoshorten"];
8: SubmitLongUrl();
9: }
10: }
11: }
I created a method [CheckQueryString()] to be called during the default.aspx's Page_Load to do the following:
- Line 3 - See if a QueryString collection was provided. If not, then do nothing else.
- Line 5 - See if the first pair had a name equal to "linktoshorten" in which case I knew that I wanted to process it.
- Line 7 & 8 - If yes, then set the text of my TextBox with the value provided in the QueryString and kick off SubmitLongUrl, the method that creates a new shortLink from a long URL (with all sorts of checks and balances in place).
- If no, then do nothing else and simply display the default page.
Easy as pie, right?
Perhaps it's not the most elegant solution to the issue of reading in string values from a URL, but it works. One of the cool things about the QueryString collection is that can easily be used to pass strings from one page/site to another.
~tod
DISCLAIMER: As usual, my standard code disclaimer applies and I welcome all suggestions for improvement.