简体   繁体   English

Request.QueryString 如何工作?

[英]how does Request.QueryString work?

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 :)谢谢 :)

The HttpRequest class represents the request made to the server and has various properties associated with it, such as QueryString . HttpRequest类表示向服务器发出的请求,并具有与其关联的各种属性,例如QueryString

The ASP.NET run-time parses a request to the server and populates this information for you. ASP.NET 运行时解析对服务器的请求并为您填充此信息。

Read HttpRequest Properties for a list of all the potential properties that get populated on you behalf by ASP.NET.阅读HttpRequest 属性以获取由 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.注意:并非所有属性都会被填充,例如,如果您的请求没有查询字符串,则QueryString将为空/空。 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"]);
}

The Request object is the entire request sent out to some server. Request 对象是发送到某个服务器的整个请求。 This object comes with a QueryString dictionary that is everything after '?'这个对象带有一个 QueryString 字典,它是 '?' 之后的所有内容。 in the URL.在网址中。

Not sure exactly what you were looking for in an answer, but check out http://en.wikipedia.org/wiki/Query_string不确定您在答案中究竟要寻找什么,但请查看http://en.wikipedia.org/wiki/Query_string

Request.QueryString["pID"];

Here Request is a object that retrieves the values that the client browser passed to the server during an HTTP request and QueryString is a collection is used to retrieve the variable values in the HTTP query string. Request是一个对象,用于检索客户端浏览器在 HTTP 请求期间传递给服务器的值,而QueryString是一个集合,用于检索 HTTP 查询字符串中的变量值。

READ MORE@ http://msdn.microsoft.com/en-us/library/ms524784(v=vs.90).aspx阅读更多@ http://msdn.microsoft.com/en-us/library/ms524784(v=vs.90).aspx

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"

The QueryString collection is used to retrieve the variable values in the HTTP query string. QueryString 集合用于检索 HTTP 查询字符串中的变量值。

The HTTP query string is specified by the values following the question mark (?), like this: HTTP 查询字符串由问号 (?) 后面的值指定,如下所示:

Link with a query string使用查询字符串链接

The line above generates a variable named txt with the value "this is a query string test".上面的行生成一个名为 txt 的变量,其值为“这是一个查询字符串测试”。

Query strings are also generated by form submission, or by a user typing a query into the address bar of the browser.查询字符串也由表单提交生成,或者由用户在浏览器的地址栏中键入查询生成。

And see this sample : http://www.codeproject.com/Articles/5876/Passing-variables-between-pages-using-QueryString并查看此示例: http : //www.codeproject.com/Articles/5876/Passing-variables-between-pages-using-QueryString

refer this : http://www.dotnetperls.com/querystring参考这个: http : //www.dotnetperls.com/querystring

you can collect More details in google .您可以在 google 中收集更多详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM