zoukankan      html  css  js  c++  java
  • Request[ "id" ]的作用

    Request.QueryString 替我们件事情:每次接受到参数后,都做 UrlEncode ,并且是按照 UTF-8编码做的 UrlEncode 。 这在大多数情况下没有任何问题,但是一些情况下,会给我们带来麻烦,本文就是分析这些可能给我们带来麻烦的场景,以及解决方法。

    Request.QueryString["id"] 只能读取通过地址栏参数传递过来的名为id的参数。
    Request["id"]是一个复合功能读取函数。
    它的优先级顺序为
    QueryString > Form > Cookies > ServerVariables

    也就是说,如果存在名为id的地址栏参数,Request[ "id" ] 的效果和 Request.QueryString["id"] 是样的。
    如 果不存在名为id的地址栏参数,Request.QueryString["id"]将会返回空,但是Request[ "id" ]会继续检查是否存在名为id的表单提交元素,如果不存在,则继续尝试检查名为id的Cookie,如果不存在,继续检查名为id的服务器环境变量。它将 最多做出4个尝试,只有四个尝试都失败,才返回空。


    以下是Request[ "id" ]的内部实现代码:
    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;
            }
        }

  • 相关阅读:
    nodejs cheerio模块提取html页面内容
    简短的perl程序
    laravel 模型操作
    Laravel 学习笔记
    记录一下应该养成的好习惯
    phpstudy设置允许远程访问mysql数据库
    删除专家账号,要注意删干净
    使用 Composer 安装Laravel扩展包的几种方法
    上传文件太大,后台无法获取到文件的问题
    在Laravel中使用mongoDB
  • 原文地址:https://www.cnblogs.com/beidao/p/2536878.html
Copyright © 2011-2022 走看看