Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how does Request.QueryString work?

Tags:

I have a code example like this :

 location.href = location.href + "/Edit?pID=" + hTable.getObj().ID; ; //aspx      parID = Request.QueryString["pID"]; //c# 

it works, my question is - how ? what is the logic ? thanks :)

like image 287
user2560521 Avatar asked Aug 21 '13 15:08

user2560521


People also ask

How do you pass a QueryString?

To pass in parameter values, simply append them to the query string at the end of the base URL. In the above example, the view parameter script name is viewParameter1.

Why do we use request QueryString in asp net?

The QueryString collection is used to retrieve the variable values in the HTTP query string. The line above generates a variable named txt with the value "this is a query string test". Query strings are also generated by form submission, or by a user typing a query into the address bar of the browser.

What do you mean by QueryString explain with example?

A query string commonly includes fields added to a base URL by a Web browser or other client application, for example as part of an HTML, choosing the appearance of a page, or jumping to positions in multimedia content.

Is QueryString safe?

Yes, your query strings will be encrypted. The reason behind is that query strings are part of the HTTP protocol which is an application layer protocol, while the security (SSL/TLS) part comes from the transport layer.


2 Answers

The HttpRequest class represents the request made to the server and has various properties associated with it, such as QueryString.

The ASP.NET run-time parses a request to the server and populates this information for you.

Read HttpRequest Properties for a list of all the potential properties that get populated on you behalf by ASP.NET.

Note: not all properties will be populated, for instance if your request has no query string, then the QueryString will be null/empty. So you should check to see if what you expect to be in the query string is actually there before using it like this:

if (!String.IsNullOrEmpty(Request.QueryString["pID"])) {     // Query string value is there so now use it     int thePID = Convert.ToInt32(Request.QueryString["pID"]); } 
like image 156
Karl Anderson Avatar answered Sep 28 '22 11:09

Karl Anderson


A query string is an array of parameters sent to a web page.

This url: http://page.asp?x=1&y=hello  Request.QueryString[0] is the same as  Request.QueryString["x"] and holds a string value "1"  Request.QueryString[1] is the same as  Request.QueryString["y"] and holds a string value "hello" 
like image 38
Metaphor Avatar answered Sep 28 '22 13:09

Metaphor