Files
VAR.WebFormsCore/VAR.Focus.Web/Code/ExtensionMethods.cs

42 lines
1.3 KiB
C#

using System;
using System.Web;
using VAR.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);
}
public static void PrepareCacheableResponse(this HttpResponse response)
{
const int secondsInDay = 86400;
response.ExpiresAbsolute = DateTime.Now.AddSeconds(secondsInDay);
response.Expires = secondsInDay;
response.Cache.SetCacheability(HttpCacheability.Public);
response.Cache.SetMaxAge(new TimeSpan(0, 0, secondsInDay));
}
#endregion HttpContext
}
}