bklLiudl
2024-07-23 800b01a48d309fa19a624e943b3a8fb2e8eef5c8
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
using System.Runtime.InteropServices;
using System.Web;
 
namespace Common
{
    public class RequestHelper
    {
        public static string GetScriptNameQueryString
        {
            get
            {
                return HttpContext.Current.Request.ServerVariables["QUERY_STRING"].ToString();
            }
        }
 
        public static string GetScriptName
        {
            get
            {
                return HttpContext.Current.Request.ServerVariables["SCRIPT_NAME"].ToString();
            }
        }
 
        public static string GetScriptUrl
        {
            get
            {
                return (RequestHelper.GetScriptNameQueryString == "") ? RequestHelper.GetScriptName : string.Format("{0}?{1}", RequestHelper.GetScriptName, RequestHelper.GetScriptNameQueryString);
            }
        }
 
        public static string GetScriptNameQuery
        {
            get
            {
                return HttpContext.Current.Request.Url.Query;
            }
        }
 
        [DllImport("wininet")]
        private static extern bool InternetGetConnectedState(out int connectionDescription, int reservedValue);
 
        public static bool IsConnectedInternet()
        {
            int i = 0;
            return RequestHelper.InternetGetConnectedState(out i, 0);
        }
 
        public static string UrlEncode(string str)
        {
            string result;
            if (string.IsNullOrEmpty(str))
            {
                result = "";
            }
            else
            {
                str = str.Replace("'", "");
                result = HttpContext.Current.Server.UrlEncode(str);
            }
            return result;
        }
 
        public static string UrlDecode(string str)
        {
            string result;
            if (string.IsNullOrEmpty(str))
            {
                result = "";
            }
            else
            {
                result = HttpContext.Current.Server.UrlDecode(str);
            }
            return result;
        }
 
        public static string GetIP()
        {
            string result = string.Empty;
            result = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
            if (string.IsNullOrEmpty(result))
            {
                result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
            }
            if (string.IsNullOrEmpty(result))
            {
                result = HttpContext.Current.Request.UserHostAddress;
            }
            string result2;
            if (string.IsNullOrEmpty(result))
            {
                result2 = "127.0.0.1";
            }
            else
            {
                result2 = result;
            }
            return result2;
        }
 
        public static string buildurl(string url, string param)
        {
            string result;
            if (url.IndexOf(param) > 0)
            {
                string url2;
                if (url.IndexOf("&", url.IndexOf(param) + param.Length) > 0)
                {
                    url2 = url.Substring(0, url.IndexOf(param) - 1) + url.Substring(url.IndexOf("&", url.IndexOf(param) + param.Length) + 1);
                }
                else
                {
                    url2 = url.Substring(0, url.IndexOf(param) - 1);
                }
                result = url2;
            }
            else
            {
                result = url;
            }
            return result;
        }
 
        public static bool IsPost()
        {
            return HttpContext.Current.Request.HttpMethod.Equals("POST");
        }
 
        public static bool IsGet()
        {
            return HttpContext.Current.Request.HttpMethod.Equals("GET");
        }
 
        public static string GetServerString(string strName)
        {
            string result;
            if (HttpContext.Current.Request.ServerVariables[strName] == null)
            {
                result = "";
            }
            else
            {
                result = HttpContext.Current.Request.ServerVariables[strName].ToString();
            }
            return result;
        }
 
        public static string GetUrlReferrer()
        {
            string retVal = null;
            try
            {
                retVal = HttpContext.Current.Request.UrlReferrer.ToString();
            }
            catch
            {
            }
            string result;
            if (retVal == null)
            {
                result = "";
            }
            else
            {
                result = retVal;
            }
            return result;
        }
 
        public static string GetCurrentFullHost()
        {
            HttpRequest request = HttpContext.Current.Request;
            string result;
            if (!request.Url.IsDefaultPort)
            {
                result = string.Format("{0}:{1}", request.Url.Host, request.Url.Port.ToString());
            }
            else
            {
                result = request.Url.Host;
            }
            return result;
        }
 
        public static string GetHost()
        {
            return HttpContext.Current.Request.Url.Host;
        }
 
        public static string GetDnsSafeHost()
        {
            return HttpContext.Current.Request.Url.DnsSafeHost;
        }
 
        public static string GetRawUrl()
        {
            return HttpContext.Current.Request.RawUrl;
        }
 
        public static bool IsBrowserGet()
        {
            string[] BrowserName = new string[]
            {
                "ie",
                "opera",
                "netscape",
                "mozilla",
                "konqueror",
                "firefox"
            };
            string curBrowser = HttpContext.Current.Request.Browser.Type.ToLower();
            bool result;
            for (int i = 0; i < BrowserName.Length; i++)
            {
                if (curBrowser.IndexOf(BrowserName[i]) >= 0)
                {
                    result = true;
                    return result;
                }
            }
            result = false;
            return result;
        }
 
        public static bool IsSearchEnginesGet()
        {
            bool result;
            if (HttpContext.Current.Request.UrlReferrer == null)
            {
                result = false;
            }
            else
            {
                string[] SearchEngine = new string[]
                {
                    "google",
                    "yahoo",
                    "msn",
                    "baidu",
                    "sogou",
                    "sohu",
                    "sina",
                    "163",
                    "lycos",
                    "tom",
                    "yisou",
                    "iask",
                    "soso",
                    "gougou",
                    "zhongsou"
                };
                string tmpReferrer = HttpContext.Current.Request.UrlReferrer.ToString().ToLower();
                for (int i = 0; i < SearchEngine.Length; i++)
                {
                    if (tmpReferrer.IndexOf(SearchEngine[i]) >= 0)
                    {
                        result = true;
                        return result;
                    }
                }
                result = false;
            }
            return result;
        }
 
        public static string GetUrl()
        {
            return HttpContext.Current.Request.Url.ToString();
        }
 
        public static string GetPageName()
        {
            string[] urlArr = HttpContext.Current.Request.Url.AbsolutePath.Split(new char[]
            {
                '/'
            });
            return urlArr[urlArr.Length - 1].ToLower();
        }
 
        public static int GetParamCount()
        {
            return HttpContext.Current.Request.Form.Count + HttpContext.Current.Request.QueryString.Count;
        }
    }
}