Request()与Request.QueryString() [英] Request() vs Request.QueryString()
问题描述
我最近开始使用 Request("key")
而不是 Request.QueryString("key")
来访问我的查询字符串值.但是我读过:
I have recently started using Request("key")
instead of Request.QueryString("key")
to access my querystring values. However I have read that:
从System.Web.HttpRequest.Cookies获取指定的对象,System.Web.HttpRequest.Form,System.Web.HttpRequest.QueryString,System.Web.HttpRequest.ServerVariables
Gets the specified object from the System.Web.HttpRequest.Cookies, System.Web.HttpRequest.Form, System.Web.HttpRequest.QueryString, System.Web.HttpRequest.ServerVariables
因此,如果我有一个相同的querystring键和cookie键,则返回哪个值?
Therefore, if I have a querystring key and cookie key which are the same, which value is returned?
推荐答案
按以下顺序检查它们:
-
QueryString
-
表格
-
Cookies
-
ServerVariables
搜索被短路,因此一旦找到匹配的键,则返回值.
The search is short-circuited, so as soon as a matching key is found the value is returned.
因此,为回答您的问题,匹配的 QueryString
项优先于 Cookies
.
So, to answer your question, a matching QueryString
item takes precedence over Cookies
.
这篇关于Request()与Request.QueryString()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!