yzh
2021-10-09 a46339e796fc2ee56959618cf1a7ce0382c1c74c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
 
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";
  }
}