Htt的prequest索引搜索顺序 [英] Search order of HttpRequest indexer

查看:217
本文介绍了Htt的prequest索引搜索顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您通过请求[关键]做一个简单的索引要求的项目,它看起来的 4的位置。什么是订单?有人提出在饼干,ServerVariables,窗体和查询字符串的页面上的猜测。有谁知道肯定?文件将是一个奖金:)

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

推荐答案

公共字符串此[字符串键] {搞定; }

public string this[string key] { get; }

声明类型:System.Web.Htt prequest
集:System.Web,版本= 2.0.0.0

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

这篇关于Htt的prequest索引搜索顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆