洛阳中航光电项目,为12年项目,此处使用反编译工具恢复源码,恢复为.netframe4.0版本,但仍需使用ie8访问; 数据库使用oracle,现再192.168.8.3服务器,访问账户scott,密码800100

RequestBase.cs 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. using System;
  2. using System.Web;
  3. namespace Common
  4. {
  5. public class RequestBase
  6. {
  7. public static bool IsPost()
  8. {
  9. return HttpContext.Current.Request.HttpMethod.Equals("POST");
  10. }
  11. public static bool IsGet()
  12. {
  13. return HttpContext.Current.Request.HttpMethod.Equals("GET");
  14. }
  15. public static string GetServerString(string strName)
  16. {
  17. string result;
  18. if (HttpContext.Current.Request.ServerVariables[strName] == null)
  19. {
  20. result = "";
  21. }
  22. else
  23. {
  24. result = HttpContext.Current.Request.ServerVariables[strName].ToString();
  25. }
  26. return result;
  27. }
  28. public static string GetUrlReferrer()
  29. {
  30. string retVal = null;
  31. try
  32. {
  33. retVal = HttpContext.Current.Request.UrlReferrer.ToString();
  34. }
  35. catch
  36. {
  37. }
  38. string result;
  39. if (retVal == null)
  40. {
  41. result = "";
  42. }
  43. else
  44. {
  45. result = retVal;
  46. }
  47. return result;
  48. }
  49. public static string GetCurrentFullHost()
  50. {
  51. HttpRequest request = HttpContext.Current.Request;
  52. string result;
  53. if (!request.Url.IsDefaultPort)
  54. {
  55. result = string.Format("{0}:{1}", request.Url.Host, request.Url.Port.ToString());
  56. }
  57. else
  58. {
  59. result = request.Url.Host;
  60. }
  61. return result;
  62. }
  63. public static string GetHost()
  64. {
  65. return HttpContext.Current.Request.Url.Host;
  66. }
  67. public static string GetRawUrl()
  68. {
  69. return HttpContext.Current.Request.RawUrl;
  70. }
  71. public static bool IsBrowserGet()
  72. {
  73. string[] BrowserName = new string[]
  74. {
  75. "ie",
  76. "opera",
  77. "netscape",
  78. "mozilla"
  79. };
  80. string curBrowser = HttpContext.Current.Request.Browser.Type.ToLower();
  81. bool result;
  82. for (int i = 0; i < BrowserName.Length; i++)
  83. {
  84. if (curBrowser.IndexOf(BrowserName[i]) >= 0)
  85. {
  86. result = true;
  87. return result;
  88. }
  89. }
  90. result = false;
  91. return result;
  92. }
  93. public static bool IsSearchEnginesGet()
  94. {
  95. string[] SearchEngine = new string[]
  96. {
  97. "google",
  98. "yahoo",
  99. "msn",
  100. "baidu",
  101. "sogou",
  102. "sohu",
  103. "sina",
  104. "163",
  105. "lycos",
  106. "tom"
  107. };
  108. string tmpReferrer = HttpContext.Current.Request.UrlReferrer.ToString().ToLower();
  109. bool result;
  110. for (int i = 0; i < SearchEngine.Length; i++)
  111. {
  112. if (tmpReferrer.IndexOf(SearchEngine[i]) >= 0)
  113. {
  114. result = true;
  115. return result;
  116. }
  117. }
  118. result = false;
  119. return result;
  120. }
  121. public static string GetUrl()
  122. {
  123. return HttpContext.Current.Request.Url.ToString();
  124. }
  125. public static string GetQueryString(string strName)
  126. {
  127. string result;
  128. if (HttpContext.Current.Request.QueryString[strName] == null)
  129. {
  130. result = "";
  131. }
  132. else
  133. {
  134. result = HttpContext.Current.Request.QueryString[strName];
  135. }
  136. return result;
  137. }
  138. public static string GetPageName()
  139. {
  140. string[] urlArr = HttpContext.Current.Request.Url.AbsolutePath.Split(new char[]
  141. {
  142. '/'
  143. });
  144. return urlArr[urlArr.Length - 1].ToLower();
  145. }
  146. public static int GetParamCount()
  147. {
  148. return HttpContext.Current.Request.Form.Count + HttpContext.Current.Request.QueryString.Count;
  149. }
  150. public static string GetFormString(string strName)
  151. {
  152. string result;
  153. if (HttpContext.Current.Request.Form[strName] == null)
  154. {
  155. result = "";
  156. }
  157. else
  158. {
  159. result = HttpContext.Current.Request.Form[strName];
  160. }
  161. return result;
  162. }
  163. public static string GetString(string strName)
  164. {
  165. string result;
  166. if ("".Equals(RequestBase.GetQueryString(strName)))
  167. {
  168. result = RequestBase.GetFormString(strName);
  169. }
  170. else
  171. {
  172. result = RequestBase.GetQueryString(strName);
  173. }
  174. return result;
  175. }
  176. public static int GetQueryInt(string strName, int defValue)
  177. {
  178. return Utils.StrToInt(HttpContext.Current.Request.QueryString[strName], defValue);
  179. }
  180. public static int GetFormInt(string strName, int defValue)
  181. {
  182. return Utils.StrToInt(HttpContext.Current.Request.Form[strName], defValue);
  183. }
  184. public static int GetInt(string strName, int defValue)
  185. {
  186. int result;
  187. if (RequestBase.GetQueryInt(strName, defValue) == defValue)
  188. {
  189. result = RequestBase.GetFormInt(strName, defValue);
  190. }
  191. else
  192. {
  193. result = RequestBase.GetQueryInt(strName, defValue);
  194. }
  195. return result;
  196. }
  197. public static float GetQueryFloat(string strName, float defValue)
  198. {
  199. return Utils.StrToFloat(HttpContext.Current.Request.QueryString[strName], defValue);
  200. }
  201. public static float GetFormFloat(string strName, float defValue)
  202. {
  203. return Utils.StrToFloat(HttpContext.Current.Request.Form[strName], defValue);
  204. }
  205. public static float GetFloat(string strName, float defValue)
  206. {
  207. float result;
  208. if (RequestBase.GetQueryFloat(strName, defValue) == defValue)
  209. {
  210. result = RequestBase.GetFormFloat(strName, defValue);
  211. }
  212. else
  213. {
  214. result = RequestBase.GetQueryFloat(strName, defValue);
  215. }
  216. return result;
  217. }
  218. public static string GetIP()
  219. {
  220. string result = string.Empty;
  221. result = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
  222. if (result == null || result == string.Empty)
  223. {
  224. result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
  225. }
  226. if (result == null || result == string.Empty)
  227. {
  228. result = HttpContext.Current.Request.UserHostAddress;
  229. }
  230. string result2;
  231. if (result == null || result == string.Empty || !Utils.IsIP(result))
  232. {
  233. result2 = "0.0.0.0";
  234. }
  235. else
  236. {
  237. result2 = result;
  238. }
  239. return result2;
  240. }
  241. public static void SaveRequestFile(string path)
  242. {
  243. if (HttpContext.Current.Request.Files.Count > 0)
  244. {
  245. HttpContext.Current.Request.Files[0].SaveAs(path);
  246. }
  247. }
  248. }
  249. }