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


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

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;
            }

        }

    }

}
posted @ 2006-08-03 15:22  KenBlove  阅读(344)  评论(0编辑  收藏  举报