读取常用数据(1)读取Web.config,QueryString和Form(Post)

mac2022-06-30  76

又几个毫无技术含量的函数,记录一下。呵呵

using  System; using  System.Web; using  System.Configuration; // 读取web.config namespace  QS_Web {    namespace Kobold    {        public class Read        {            public static string GetConfigSetting(string strKeyName)//读取Web.config文件设置字符串            {                string str;                try                {                    str = ConfigurationSettings.AppSettings[strKeyName];//读取                }                catch                {                    str = "null";                }                if(str == null || str == String.Empty)                {                    return "null";                }                else                {                    return str;                }            }            public static string GetQueryString(string strParameterName)//获取Url Query String            {                string str;                try                {                    if (HttpContext.Current.Request.QueryString[strParameterName]!=null)                    {                        str = HttpContext.Current.Request.QueryString[strParameterName];                    }                    else                    {                        str = "null";                    }                }                catch                {                    str = "error";                }                return str;            }            public static string GetForm(string strName)//获取 post Form            {                string str;                try                {                    if (HttpContext.Current.Request.Form[strName]!=null)                    {                        str = HttpContext.Current.Request.Form[strName];                    }                    else                    {                        str = "null";                    }                }                catch                {                    str = "error";                }                return str;            }        }    }}

转载于:https://www.cnblogs.com/KenBlove/articles/466821.html

最新回复(0)