首页 > Web开发 > 详细

httpHelper 从URL获取值

时间:2017-06-09 23:16:41      阅读:323      评论:0      收藏:0      [点我收藏+]
/// <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获取值

原文:http://www.cnblogs.com/sanday/p/6974051.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!