Request()vs Request.QueryString()

Cur*_*urt 9 vb.net asp.net

我最近开始使用Request("key")而不是Request.QueryString("key")访问我的查询字符串值.不过我读过:

从System.Web.HttpRequest.Cookies,System.Web.HttpRequest.Form,System.Web.HttpRequest.QueryString,System.Web.HttpRequest.ServerVariables获取指定的对象.

因此,如果我有一个相同的查询字符串键和cookie键,返回哪个值?

Luk*_*keH 18

它们按以下顺序检查:

  1. QueryString
  2. Form
  3. Cookies
  4. ServerVariables

搜索被短路,因此一旦找到匹配的键,就返回该值.

因此,要回答您的问题,匹配QueryString项优先于Cookies.

  • 有关更多信息,请参阅Scott Hanselman关于此内容的优秀博客文章http://www.hanselman.com/blog/ASPNETParamsCollectionVsQueryStringFormsVsRequestindexAndDoubleDecoding.aspx (3认同)