How to Read Data From Query String In ASP.NET

Learn how to read data from a query string in ASP.NET using C#.

Query string is a method of transferring data from one page to another via a URL. The value is passed as a part of the full URL of the page. 
 
Let's say, you need to pass a user ID and name from one page to other page, here is a URL:
 
Http://www.abc.com?userid=1234& name=somename
 
In the above URL, the userid and name are two query string parameters with their values passed as a part of the URL. 
 
Now, on the next page, we can read these values on the page and use them on our page. To read the query string values back in ASP.NET, we can use Request.QueryString of the page.
 
The following code snippet reads query string values. 
 
string userid = Request.QueryString["userid"].ToString();
string name = Request.QueryString["name"].ToString();
 
Values are returned in string format that you need to convert if required.
 
Note: Query strings are not a secure way or recommended way to transfer sensitive data.  
 
Here is a detailed tutorial on, How to Use Query Strings in ASP.NET.