using Common; using System; using System.Text; using System.Web; using System.Web.SessionState; public class HandlerContext { public HttpContext Context { get; set; } public HttpFileCollection Files { get { return this.Context.Request.Files; } } public HttpSessionState Session { get { return this.Context.Session; } } public HttpResponse Response { get { return this.Context.Response; } } public HttpRequest Request { get { return this.Context.Request; } } public string ClientIP { get { string str1 = this.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; string str2; if (string.IsNullOrEmpty(str1) || str1.ToLower() == "unknown") { str2 = this.Request.ServerVariables["HTTP_X_REAL_IP"]; if (string.IsNullOrEmpty(str2)) str2 = this.Request.ServerVariables["REMOTE_ADDR"]; } else str2 = str1.Split(',')[0]; return str2; } } public string RootDir { get { return this.Context.Server.MapPath("/"); } } public HandlerContext(HttpContext context) { this.Context = context; } public string GetString(string fieldName) { return TypeConvert.ToString((object) this.Context.Request[fieldName]).Trim(); } public string GetString(string fieldName, string dv) { if (this.Context.Request[fieldName] == null) return dv; return this.GetString(fieldName); } public int GetInt(string fieldName, int defaultV) { string @string = this.GetString(fieldName); if (string.IsNullOrEmpty(@string)) return defaultV; return TypeConvert.ToInt32((object) @string, defaultV); } public int GetInt(string fieldName) { return TypeConvert.ToInt32((object) this.GetString(fieldName)); } public long GetInt64(string fieldName) { return TypeConvert.ToInt64((object) this.GetString(fieldName)); } public DateTime GetDateTime(string fieldName) { return TypeConvert.ToDateTime((object) this.GetString(fieldName)); } public bool GetBoolean(string fieldName) { string @string = this.GetString(fieldName); return string.Equals("true", @string, StringComparison.OrdinalIgnoreCase) || string.Equals("1", @string) || TypeConvert.ToBoolean((object) @string); } public Decimal GetDecimal(string fieldName, Decimal v) { v = 0.0M; return TypeConvert.ToDecimal((object) this.GetString(fieldName), v); } public void RemoveCookie(string key) { this.Context.Response.Cookies.Remove(key); } public virtual void SetCookie(string key, string value, string domain) { this.Context.Response.SetCookie(new HttpCookie(key, value) { Expires = DateTime.Now.AddDays(7.0), Path = "/", Domain = domain }); } public string GetCookie(string key) { HttpCookie httpCookie = this.Context.Request.Cookies.Get(key); return httpCookie == null ? string.Empty : httpCookie.Value; } internal string GetRequestData() { StringBuilder stringBuilder = new StringBuilder(); for (int index = 0; index < this.Context.Request.QueryString.Count; ++index) { if (this.Context.Request.QueryString.GetKey(index) != "r") stringBuilder.Append(this.Context.Request.QueryString[index] + ";"); } return stringBuilder.ToString(); } internal string GetClientAddress() { string str = this.Context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; if (string.IsNullOrEmpty(str)) str = this.Context.Request.ServerVariables["REMOTE_ADDR"]; if (string.IsNullOrEmpty(str)) str = this.Context.Request.UserHostAddress; if (!string.IsNullOrEmpty(str)) return str; return "0.0.0.0"; } }