Home > Backend Development > C#.Net Tutorial > httpHelper example code to get value from URL

httpHelper example code to get value from URL

零下一度
Release: 2017-06-23 16:14:21
Original
1628 people have browsed it
/// <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, "&#39;", "&#39;&#39;");
            return str;
        }
Copy after login

  

The above is the detailed content of httpHelper example code to get value from URL. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template