httpHelper 从URL获取值_.NET_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > .NET > httpHelper 从URL获取值

httpHelper 从URL获取值

 2017/6/10 5:33:04  1390193352  程序员俱乐部  我要评论(0)
  • 摘要:///<summary>///从URL获取值(字符串)///</summary>publicstaticstringGetValueFromUrl(stringkey){stringkeyvalue=HttpContext.Current.Request.QueryString[key];if(keyvalue!=null){keyvalue=KillBadString(keyvalue);returnkeyvalue;}return"";}///<
  • 标签:URL HTTP
class="brush:csharp;gutter:true;">/// <summary>
        /// 从URL获取值(字符串)
        /// </summary>
        public static string GetValueFromUrl(string key)
        {
            string keyvalue = HttpContext.Current.Request.QueryString[key];
            if (keyvalue != null)
            {
                keyvalue = KillBadString(keyvalue);

                return keyvalue;
            }
            return "";
        }
        /// <summary>
        /// 从URL获取值(整型)
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static int GetIntValueFromUrl(string key)
        {
            string keyvalue = HttpContext.Current.Request.QueryString[key];
            int result = 0;

            if (int.TryParse(keyvalue, out result))
            {
                return result;
            }

            return result;
        }

        /// <summary>
        /// 过滤SQL敏感字符
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string KillBadString(string str)
        {
            if (str == null || str.Length == 0)
            {
                return "";
            }
            str = System.Text.RegularExpressions.Regex.Replace(str, "'", "''");
            return str;
        }

  

发表评论
用户名: 匿名