欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

httpHelper 从URL获取值的实例代码

程序员文章站 2022-03-22 13:30:21
...
/// <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;
        }

  

以上就是httpHelper 从URL获取值的实例代码的详细内容,更多请关注其它相关文章!

相关标签: httpHelper 取值