Using System.Web;
Using System.Text.RegularExpressions;
namespace Dotnet.utilities
{
// <summary>
/// QueryString Address bar parameters
// </summary>
Public class QueryString
{
#region equals request.querystring, if NULL returns NULL "", returns Request.querystring[name]
// <summary>
/// equals request.querystring; returns null "" If NULL, otherwise returns REQUEST.QUERYSTRING[NAME]
// </summary>
// <param name= "name" ></param>
// <returns></returns>
Public static string Q (string name)
{
return Request.querystring[name] = = null? "": Request.querystring[name];
}
#endregion
//<summary>
//equals Request.Form returns NULL if NULL "", return Request.form[name]
//</summary>
//<param name= "name" ></PARAM>
///<returns></returns>
public static string F (string name)
return request.form[name] = = Null? "": Request.form[name]. ToString ();
#region gets the ID in the URL
//<summary
///get the ID in the URL
//</ Summary>
///<param name= "name" ></PARAM>
///<returns></returns>
public static int QId (string name)
return Strtoid (Q (name));
#endregion
#region gets the correct ID, if not a positive integer, returns 0
// <summary>
///get the correct ID, if not a positive integer, return 0
//</summary>
///<param name= "_value" ></PARAM>
///<returns> returns the correct integer ID, failed to return 0</RETURNS>
public static int strtoid (string _value)
if (Isnumberid (_value))
return int. Parse (_value);
else
return 0;
#endregion
#region checks whether a string is a purely numeric character and is typically used for validation of query string parameters.
<summary>
Checks whether a string is a purely numeric component, and is typically used to validate validation of query string parameters.
</summary>
<param name= "_value" > String to be validated: </param>
<returns> is a valid bool value. </returns>
public static bool Isnumberid (string _value)
{
Return Quickvalidate ("^[1-9]*[0-9]*$", _value);
}
#endregion
#region quickly verifies that a string conforms to the specified regular expression.
// <summary>
/// fast verifies whether a string conforms to the specified regular expression.
// </summary>
/// <param name= "_express" > Regular expression content. </param>
/// <param name= "_value" > string to be validated. </param>
// <returns> is a valid bool value. </returns>
Public static bool Quickvalidate (string _express, string _value)
{
if (_value = = null) return false;
regex myregex = new Regex (_express);
if (_value. Length = = 0)
{
return false;
}
return Myregex.ismatch (_value);
}
#endregion
#region class Internal invocation
// <summary>
// HttpContext Current
// </summary>
Public static HttpContext Current
{
get {return httpcontext.current;}
}
// <summary>
/// HttpContext current HttpRequest Request get {return current.request;
// </summary>
Public static HttpRequest Request
{
get {return current.request;}
}
// <summary>
/// HttpContext current HttpRequest Request get {return current.request; HttpResponse Response return current.response;
// </summary>
Public static HttpResponse Response
{
get {return current.response;}
}
#endregion
}
}
QueryString Address bar parameters