HttpRequest 索引器的搜索顺序

发布于 2024-08-09 06:49:39 字数 242 浏览 4 评论 0原文

如果您通过 Request[key] 对请求的项目进行简单索引,它将在 4 个地点。有什么顺序吗?有人在该页面上猜测“Cookies、ServerVariables、Form 和 QueryString”。有谁确切知道吗?文档将是一个额外的好处:)

If you do a simple index into Request's items via Request[key], it looks in 4 locations. What's the order? Someone makes a guess on that page at "Cookies, ServerVariables, Form and QueryString". Does anyone know for sure? Documentation would be a bonus :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

很酷又爱笑 2024-08-16 06:49:39

公共字符串this[字符串键] { get; }

声明类型:System.Web.HttpRequest 程序集:System.Web,
版本=2.0.0.0

public string this[string key]
{
    get
    {
        string str = this.QueryString[key];
        if (str != null)
        {
            return str;
        }
        str = this.Form[key];
        if (str != null)
        {
            return str;
        }
        HttpCookie cookie = this.Cookies[key];
        if (cookie != null)
        {
            return cookie.Value;
        }
        str = this.ServerVariables[key];
        if (str != null)
        {
            return str;
        }
        return null;
    }
}

public string this[string key] { get; }

Declaring Type: System.Web.HttpRequest Assembly: System.Web,
Version=2.0.0.0

public string this[string key]
{
    get
    {
        string str = this.QueryString[key];
        if (str != null)
        {
            return str;
        }
        str = this.Form[key];
        if (str != null)
        {
            return str;
        }
        HttpCookie cookie = this.Cookies[key];
        if (cookie != null)
        {
            return cookie.Value;
        }
        str = this.ServerVariables[key];
        if (str != null)
        {
            return str;
        }
        return null;
    }
}
你丑哭了我 2024-08-16 06:49:39

只需使用Reflector,您就可以亲自看到它。顺序是 QueryString、Form、Cookies,然后是 ServerVariables。

Just use Reflector and you can see it for yourself. The order is QueryString, Form, Cookies, then ServerVariables.

缱倦旧时光 2024-08-16 06:49:39

这是来自 ASP 站点,但它仍然适用于 ASP。网:

所有请求对象变量都可以
直接通过调用访问
请求(变量)不带
集合名称。在这种情况下,网络
服务器搜索集合中
以下顺序:

  1. 查询字符串
  2. 表格
  3. Cookie
  4. 客户证书
  5. 服务器变量

This is from an ASP site, but it still applies to ASP.NET:

All request object variables can be
accessed directly by calling
Request(variable) without the
collection name. In this case, the Web
server searches the collections in the
following order:

  1. QueryString
  2. Form
  3. Cookies
  4. ClientCertificate
  5. ServerVariables
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文