获取参数值,不存在时返回预设值
///帮助类
public sealed class RequestHelper
{
///获取参数值,不存在的时候返回默认值
public static T Get<T>(string name, T defaultValue)
{
if (string.IsNullOrEmpty(name))
{
throw new ArgumentNullException("name is null!");
}
object value = HttpContext.Current.Request[name];
if (value != null)
{
return (T)value;
}
else
{
return defaultValue;
}
}
}
eg.
string target = RequestHelper.Get("target", "").ToLower();