What is Query String

Query String

Query String is a group of keywords that send request to the web server. These requests are used to pass information (parameters) from one page to another and you can access those information in receiving page. It containing in the HTTP requests for a specific URL. These requests specified by the values following the ? (question mark). The ? (question mark)is used as a separator and it is not part of the query string.



How to create a Query String ?

You can create a new writeable instance of HttpValueCollection by calling System.Web.HttpUtility.ParseQueryString(string.Empty).

NameValueCollection queryString = System.Web.HttpUtility.ParseQueryString(string.Empty); queryString["param1"] = "paramValue1"; queryString["param2"] = "paramValue2";

How to retrieve Query String ?

The QueryString collection retrieves the values of the variables in the HTTP query string and it is specified by the values following the ? (question mark).

protected void Page_Load(object sender, EventArgs e) { string param1 = Request.QueryString["param1"]; string param2 = Request.QueryString["param2"]; }

Query String - limitations

Query Strings have some limitations also. Query String have a length limitation because of this limitation when you have to send a lot of information it won't work. Another limitation is that Query string data is directly visible to user so this information can be falsified by malicious users and it leading to security problems.