Difference between revisions of "ASP.NET Query Strings"

From JholJhapata
(Created page with "'''Query string''' is one of the techniques in Web applications to send data from one page to another. A query string consists of two parts, field and value, and each of pair...")
 
 
Line 18: Line 18:
 
| index || Optional. Specifies one of multiple values for a variable. From 1 to Request.QueryString(variable).Count
 
| index || Optional. Specifies one of multiple values for a variable. From 1 to Request.QueryString(variable).Count
 
|}
 
|}
 +
URL in browser:
 +
    https://jholjhapata.com/wiki/ASP.NET_Query_Strings?firstname=Soumya&lastname=Das
 +
'''Query string is''': firstname=Soumya and lastname=Das
 +
 +
C# code to get Query string values on page:
 +
    string firstname = Request.QueryString["firstname"];
 +
    string lastname = Request.QueryString["lastname"];

Latest revision as of 17:51, 4 February 2020

Query string is one of the techniques in Web applications to send data from one page to another. A query string consists of two parts, field and value, and each of pair separated by ampersand (&).

The ?(question mark in a query string indicates the beginning of a query string and it's value.

Query strings cannot be used to send very long data as there is a limit on the Query string length.

Query strings are visible to the user, hence should not be used to send sensitive information suck as a username and password, unless encrypted.

To retrieve the query string value, use Request object's Query String property.

   Request.QueryString(variable)[(index) |.Count]
Parameter Description
variable Required. The name of the variable in the HTTP query string to retrieve
index Optional. Specifies one of multiple values for a variable. From 1 to Request.QueryString(variable).Count

URL in browser:

   https://jholjhapata.com/wiki/ASP.NET_Query_Strings?firstname=Soumya&lastname=Das

Query string is: firstname=Soumya and lastname=Das

C# code to get Query string values on page:

   string firstname = Request.QueryString["firstname"];
   string lastname = Request.QueryString["lastname"];