zoukankan      html  css  js  c++  java
  • Request.QueryString与Request的区别

    Request.Form可以获取表单中提交的内容,对于单选则会自定进行判断获取选中的值。

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

    asp.net core 交流群:787464275 欢迎加群交流
    如果您认为这篇文章还不错或者有所收获,您可以点击右下角的【推荐】按钮精神支持,因为这种支持是我继续写作,分享的最大动力!

    作者:LouieGuo
    声明:原创博客请在转载时保留原文链接或者在文章开头加上本人博客地址,如发现错误,欢迎批评指正。凡是转载于本人的文章,不能设置打赏功能,如有特殊需求请与本人联系!
    LouieGuo
  • 相关阅读:
    use tomcat to access the file cross the environment
    data audit on hadoop fs
    Good practice release jar to Nexus
    套路!从Ruby 到 Cocoapods的发布
    单元测试之NSNull 检测
    UIwebView 和 H5交互详情
    IT 需要知道的一些专业名词和解释 (长期更新)
    Git 操作 学习资源 网址
    GCD
    软件工程——个人总结
  • 原文地址:https://www.cnblogs.com/guolianyu/p/3851218.html
Copyright © 2011-2022 走看看