zoukankan      html  css  js  c++  java
  • HttpRequest this属性

    我们在做asp.net的时候往往要取客户端的数据。一般的写法都是

      var q = Request.QueryString["xxx"];
                var f = Request.Form["xxx"];
                var c = Request.Cookies["xxx"].Value;
                var s = Request.ServerVariables["xxx"];

    而我一般的写法是   var val = Request["xxx"];

    虽然这种写法很简单但是问题也比较突出,如果QueryString、Form、Cookies、ServerVariables含有相同值得时候取那个值了?

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

    要注意的地方时QueryString、Form、Cookies这3个都是客服端取到的,在asp.net4.0里面 都是做了验证的,验证的方法是RequestValidator.IsValidRequestString。根据具体情况可以重写该类的方法。

  • 相关阅读:
    eclipse的快捷键【转载】
    eclipse调试断点【转载】
    eclipse打断点的调试
    Oracle存储过程的调试
    QT5线程关闭
    QT5 Thread线程
    QT5 文件读写操作
    QT5 Even 事件
    Qt 5 常用类及基本函数
    静态库lib、动态库dll基础
  • 原文地址:https://www.cnblogs.com/majiang/p/2756104.html
Copyright © 2011-2022 走看看