获得URL参数
2015-12-05 09:23:02 访问(1362) 赞(0) 踩(0)
/// <summary>
/// 获得URL参数
/// </summary>
/// <param name="sParam"></param>
/// <returns></returns>
public static string GetParameter(string sParam)
{
string theValue = HttpContext.Current.Request.QueryString[sParam];
if (theValue == null || theValue.Length == 0)
return "";
theValue = HttpContext.Current.Server.UrlDecode(theValue);
return theValue.Trim();
}
/// <summary>
/// 获得Int参数
/// </summary>
/// <param name="sParam"></param>
/// <returns></returns>
public static int GetIntParameter(string sParam)
{
string theValue = HttpContext.Current.Request.QueryString[sParam];
if (theValue == null || theValue.Length == 0)
return 0;
int theResult = 0;
if (int.TryParse(theValue, out theResult))
return theResult;
return 0;
}
/// <summary>
/// 获得Int参数
/// </summary>
/// <param name="context"></param>
/// <param name="sParam"></param>
/// <returns></returns>
public static int GetIntParameter(HttpContext context, string sParam)
{
string theValue = context.Request.QueryString[sParam];
if (theValue == null || theValue.Length == 0)
return 0;
int theResult = 0;
if (int.TryParse(theValue, out theResult))
return theResult;
return 0;
}
/// <summary>
/// 获得Int参数
/// </summary>
/// <param name="sParam"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static int GetIntParameter(string sParam, int defaultValue)
{
string theValue = HttpContext.Current.Request.QueryString[sParam];
if (theValue == null || theValue.Length == 0)
return defaultValue;
int theResult = 0;
if (int.TryParse(theValue, out theResult))
return theResult;
return defaultValue;
}
/// <summary>
/// 获得Int参数
/// </summary>
/// <param name="context"></param>
/// <param name="sParam"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static int GetIntParameter(HttpContext context, string sParam, int defaultValue)
{
string theValue = context.Request.QueryString[sParam];
if (theValue == null || theValue.Length == 0)
return defaultValue;
int theResult = 0;
if (int.TryParse(theValue, out theResult))
return theResult;
return defaultValue;
}
/// <summary>
/// 获得Long参数
/// </summary>
/// <param name="sParam"></param>
/// <returns></returns>
public static long GetLongIDParameter()
{
string theValue = HttpContext.Current.Request.QueryString["id"];
if (theValue == null || theValue.Length == 0)
return 0;
long theResult = 0;
if (long.TryParse(theValue, out theResult))
return theResult;
return 0;
}
/// <summary>
/// 获得Long参数
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public static long GetLongIDParameter(HttpContext context)
{
string theValue = context.Request.QueryString["id"];
if (theValue == null || theValue.Length == 0)
return 0;
long theResult = 0;
if (long.TryParse(theValue, out theResult))
return theResult;
return 0;
}
/// <summary>
/// 获得Long参数
/// </summary>
/// <param name="sParam"></param>
/// <returns></returns>
public static long GetLongParameter(string sParam)
{
string theValue = HttpContext.Current.Request.QueryString[sParam];
if (theValue == null || theValue.Length == 0)
return 0;
long theResult = 0;
if (long.TryParse(theValue, out theResult))
return theResult;
return 0;
}
/// <summary>
/// 获得Long参数
/// </summary>
/// <param name="context"></param>
/// <param name="sParam"></param>
/// <returns></returns>
public static long GetLongParameter(HttpContext context, string sParam)
{
string theValue = context.Request.QueryString[sParam];
if (theValue == null || theValue.Length == 0)
return 0;
long theResult = 0;
if (long.TryParse(theValue, out theResult))
return theResult;
return 0;
}
/// <summary>
/// 获得Long参数
/// </summary>
/// <param name="sParam"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static long GetLongParameter(string sParam, long defaultValue)
{
string theValue = HttpContext.Current.Request.QueryString[sParam];
if (theValue == null || theValue.Length == 0)
return defaultValue;
long theResult = 0;
if (long.TryParse(theValue, out theResult))
return theResult;
return defaultValue;
}
/// <summary>
/// 获得Long参数
/// </summary>
/// <param name="context"></param>
/// <param name="sParam"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static long GetLongParameter(HttpContext context, string sParam, long defaultValue)
{
string theValue = context.Request.QueryString[sParam];
if (theValue == null || theValue.Length == 0)
return defaultValue;
long theResult = 0;
if (long.TryParse(theValue, out theResult))
return theResult;
return defaultValue;
}
/// <summary>
/// 获得DateTime参数
/// </summary>
/// <param name="sParam"></param>
/// <returns></returns>
public static DateTime GetDateTimeParameter(string sParam)
{
string theValue = HttpContext.Current.Request.QueryString[sParam];
if (theValue == null || theValue.Length == 0)
return DateTime.MinValue;
DateTime theResult = DateTime.MinValue;
if (DateTime.TryParse(theValue, out theResult))
return theResult;
return DateTime.MinValue;
}
/// <summary>
/// 获得DateTime参数
/// </summary>
/// <param name="sParam"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static DateTime GetDateTimeParameter(string sParam, DateTime defaultValue)
{
string theValue = HttpContext.Current.Request.QueryString[sParam];
if (theValue == null || theValue.Length == 0)
return defaultValue;
DateTime theResult = DateTime.MinValue;
if (DateTime.TryParse(theValue, out theResult))
return theResult;
return defaultValue;
}
/// <summary>
/// 获得 Boolean 参数
/// </summary>
/// <param name="sParam"></param>
/// <returns></returns>
public static bool GetBooleanParameter(string sParam)
{
string theValue = HttpContext.Current.Request.QueryString[sParam];
if (theValue == null || theValue.Length == 0)
return false;
if (theValue == CommonValueSlowXFunctionsCommon.STR_TRUE)
return true;
else
return false;
}
/// <summary>
/// 获得 Boolean 参数
/// </summary>
/// <param name="context"></param>
/// <param name="sParam"></param>
/// <returns></returns>
public static bool GetBooleanParameter(HttpContext context,string sParam)
{
string theValue = context.Request.QueryString[sParam];
if (theValue == null || theValue.Length == 0)
return false;
if (theValue == CommonValueSlowXFunctionsCommon.STR_TRUE)
return true;
else
return false;
}
/// <summary>
/// 获得 Boolean 参数
/// </summary>
/// <param name="sParam"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static bool GetBooleanParameter(string sParam, bool defaultValue)
{
string theValue = HttpContext.Current.Request.QueryString[sParam];
if (theValue == null || theValue.Length == 0)
return defaultValue;
switch (theValue)
{
case CommonValueSlowXFunctionsCommon.STR_TRUE:
return true;
case CommonValueSlowXFunctionsCommon.STR_FALSE:
return false;
default:
return defaultValue;
}
}
/// <summary>
/// 获得 Boolean 参数
/// </summary>
/// <param name="context"></param>
/// <param name="sParam"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static bool GetBooleanParameter(HttpContext context, string sParam, bool defaultValue)
{
string theValue = context.Request.QueryString[sParam];
if (theValue == null || theValue.Length == 0)
return defaultValue;
switch (theValue)
{
case CommonValueSlowXFunctionsCommon.STR_TRUE:
return true;
case CommonValueSlowXFunctionsCommon.STR_FALSE:
return false;
default:
return defaultValue;
}
}
/// <summary>
/// 获得 Boolean 参数
/// </summary>
/// <param name="sParam"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static bool? GetBooleanNullParameter(string sParam)
{
string theValue = HttpContext.Current.Request.QueryString[sParam];
if (theValue == null || theValue.Length == 0)
return null;
switch (theValue)
{
case CommonValueSlowXFunctionsCommon.STR_TRUE:
return true;
case CommonValueSlowXFunctionsCommon.STR_FALSE:
return false;
default:
return null;
}
}
/// <summary>
/// 获得 Boolean 参数
/// </summary>
/// <param name="sParam"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static bool? GetBooleanNullParameter(string sParam, bool? defaultValue)
{
string theValue = HttpContext.Current.Request.QueryString[sParam];
if (theValue == null || theValue.Length == 0)
return null;
switch (theValue)
{
case CommonValueSlowXFunctionsCommon.STR_TRUE:
return true;
case CommonValueSlowXFunctionsCommon.STR_FALSE:
return false;
default:
return defaultValue;
}
}
标签:
获得URL参数 


上一条:
下一条:
相关评论
发表评论