Move GetRequestParm and ResponseObject to extension methods
This commit is contained in:
33
VAR.Focus.Web/Code/ExtensionMethods.cs
Normal file
33
VAR.Focus.Web/Code/ExtensionMethods.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System.Web;
|
||||
using VAR.Focus.Web.Code.JSON;
|
||||
|
||||
namespace VAR.Focus.Web.Code
|
||||
{
|
||||
public static class ExtensionMethods
|
||||
{
|
||||
#region HttpContext
|
||||
|
||||
public static string GetRequestParm(this HttpContext context, string parm)
|
||||
{
|
||||
foreach (string key in context.Request.Params.AllKeys)
|
||||
{
|
||||
if (string.IsNullOrEmpty(key) == false && key.EndsWith(parm))
|
||||
{
|
||||
return context.Request.Params[key];
|
||||
}
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
public static void ResponseObject(this HttpContext context, object obj)
|
||||
{
|
||||
var jsonWritter = new JSONWriter(true);
|
||||
context.Response.ContentType = "text/json";
|
||||
string strObject = jsonWritter.Write(obj);
|
||||
context.Response.Write(strObject);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user