c# - HttpRequest 索引器的搜索顺序

标签 c# asp.net request httprequest

如果您通过 Request[key] 对 Request 的项目进行简单索引,它会在 4 locations 中查找.顺序是什么?有人在该页面上的“Cookies、ServerVariables、Form 和 QueryString”处进行了猜测。有人有确切消息么?文档将是一个奖励:)

最佳答案

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;
    }
}

关于c# - HttpRequest 索引器的搜索顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1632969/

相关文章:

c# - 响应式扩展源代码中的 NO_PERF 标志在做什么

javascript - 带有隐藏 css 的元素不会随 javascript .show() 改变

asp.net - 如何在 linq to sql 中删除?

http - 在负载测试下,Node.js Http.request变慢了。难道我做错了什么?

python - 在哪里可以找到函数的 kwargs/args 文档

c# - 无法将方法组 '' 转换为非委托(delegate)类型 'System.Delegate'。您是否打算调用该方法?

c# - 在浏览器中打开 Word 文档并进行内联编辑

c# - 我如何强制禁用元素的 wpf 窗口/控件刷新

.net - 带有页面刷新和书签的 ASP.NET ViewState 回发

javascript - NodeJS 异步库不会异步发送请求