/// <summary> /// 通过GET方式获取页面的方法 /// </summary> /// <param name="urlString">请求的URL</param> /// <param name="encoding">页面编码</param> /// <param name="sAgent">User-agentHTTP 标头的值</param> public static string GetHtmlFromGet(string urlString, Encoding encoding, string sAgent) { string htmlString = string.Empty; try { HttpWebRequest request = WebRequest.Create(urlString) as HttpWebRequest; request.Referer = urlString; request.UserAgent = sAgent; using (WebResponse response = request.GetResponse()) { using (Stream stream = response.GetResponseStream()) { using (StreamReader reader = new StreamReader(stream, encoding)) { htmlString = reader.ReadToEnd(); } } } } catch (Exception ex) { BaseLog olog = new BaseLog(ConstFolderName); olog.SaveLog(ex); } return htmlString; }
/// <summary> /// 通过GET方式获取页面的方法 /// </summary> /// <param name="urlString">请求的URL</param> /// <param name="encoding">页面编码</param> /// <param name="sAgent">User-agentHTTP 标头的值</param> public static string GetHtmlFromGet(string urlString, Encoding encoding, string sAgent) { string htmlString = string.Empty; try { HttpWebRequest request = WebRequest.Create(urlString) as HttpWebRequest; request.Referer = urlString; request.UserAgent = sAgent; using (WebResponse response = request.GetResponse()) { using (Stream stream = response.GetResponseStream()) { using (StreamReader reader = new StreamReader(stream, encoding)) { htmlString = reader.ReadToEnd(); } } } } catch (Exception ex) { BaseLog olog = new BaseLog(ConstFolderName); olog.SaveLog(ex); } return(htmlString); }
public ActiveLog() { // // TODO: 在此处添加构造函数逻辑 // this.oBaselog = new BaseLog("LActiveTest"); this.otime = new System.Timers.Timer(); this.otime.Interval = 10000; this.otime.Elapsed += new System.Timers.ElapsedEventHandler(otime_Elapsed); this.otime.Start(); this._listSql = new List<LogSql>(); }
protected void Page_Load(object sender, EventArgs e) { try { Response.ContentType = "application/Json"; Response.Charset = "utf-8"; if (Request["remote"] != null) { string className = ""; string method = ""; string route = Request["remote"] ?? ""; int index = route.LastIndexOf("."); if (index != -1) { className = route.Substring(0, index); if (route.Length > index) { method = route.Substring(index + 1, route.Length - index - 1); } } Type type = Type.GetType(string.Format("ZyGames.OA.BLL.Remote.{0}Remote,ZyGames.OA.BLL", className)); if (type != null) { object[] args = new object[] { HttpContext.Current }; var obj = (GameRemote)Activator.CreateInstance(type, args); obj.Request(method); } } else { string actionId = Convert.ToString(Request.Params["action"]); object[] args = new object[] { actionId, HttpContext.Current }; BaseAction baseAction = BaseAction.CreateInstance(actionId, args); if (baseAction != null) { baseAction.Init(); baseAction.Proccess(); } } } catch (Exception ex) { Response.Write(new JsonObject().Add("state", false).Add("message", "出错:" + ex.Message + ex.StackTrace).ToJson()); BaseLog log = new BaseLog(); log.SaveLog(ex); } }
protected void Page_Load(object sender, EventArgs e) { try { Response.ContentType = "application/Json"; Response.Charset = "utf-8"; string actionId = Convert.ToString(Request.Params["action"]); object[] args = new object[] { actionId, HttpContext.Current }; BaseAction baseAction = BaseAction.CreateInstance(actionId, args); if (baseAction != null) { baseAction.Proccess(); } } catch (Exception ex) { Response.Write(new JsonObject().Add("state", false).Add("message", "出错:" + ex.Message).ToJson()); BaseLog log = new BaseLog(); log.SaveLog(ex); } }
/// <summary> /// 提供通过POST方法获取页面的方法 /// </summary> /// <param name="urlString">请求的URL</param> /// <param name="postDataString">POST数据</param> /// <param name="encoding">页面使用的编码</param> public static string GetHtmlFromPost(string urlString, string postDataString, Encoding encoding) { string htmlString = string.Empty; try { byte[] postDataByte = encoding.GetBytes(postDataString); HttpWebRequest request = WebRequest.Create(urlString) as HttpWebRequest; request.Method = "POST"; request.KeepAlive = false; request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = postDataByte.Length; using (Stream inputStream = request.GetRequestStream()) { inputStream.Write(postDataByte, 0, postDataByte.Length); } using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { using (Stream outputStream = response.GetResponseStream()) { using (StreamReader reader = new StreamReader(outputStream, encoding)) { htmlString = reader.ReadToEnd(); } } } } catch (Exception ex) { BaseLog olog = new BaseLog(ConstFolderName); olog.SaveLog(ex); } return(htmlString); }
/// <summary> /// 提供通过POST方法获取页面的方法 /// </summary> /// <param name="urlString">请求的URL</param> /// <param name="postDataString">POST数据</param> /// <param name="encoding">页面使用的编码</param> public static string GetHtmlFromPost(string urlString, string postDataString, Encoding encoding) { string htmlString = string.Empty; try { byte[] postDataByte = encoding.GetBytes(postDataString); HttpWebRequest request = WebRequest.Create(urlString) as HttpWebRequest; request.Method = "POST"; request.KeepAlive = false; request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = postDataByte.Length; using (Stream inputStream = request.GetRequestStream()) { inputStream.Write(postDataByte, 0, postDataByte.Length); } using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { using (Stream outputStream = response.GetResponseStream()) { using (StreamReader reader = new StreamReader(outputStream, encoding)) { htmlString = reader.ReadToEnd(); } } } } catch(Exception ex) { BaseLog olog = new BaseLog(ConstFolderName); olog.SaveLog(ex); } return htmlString; }
/// <summary> /// 当参数=True时,检测是否有登录Cookie存在 /// </summary> /// <param name="aCheckLoginCookie"></param> private void LoadBasePage(bool aCheckLoginCookie) { this.oBaseLog = new BaseLog(); E_Response = System.Web.HttpContext.Current.Response; E_Request = System.Web.HttpContext.Current.Request; iUserId = CstConfig.UserIDErr; //BaseCookie oBaseSession = new BaseCookie(); //if (!oBaseSession.LoadCookie()) //{ // if (aCheckLoginCookie) // { // this.LoginError("您未登录或登录已失效"); // } //} //iUserId = oBaseSession.UserId; //string thisPageUrl = E_Request.Url.ToString().Replace(UrlBase, "").ToLower(); //if (aCheckLoginCookie) //{ // if (!IsPermitIp(oBaseLog.GetRealIP())) // { // this.LoginError("您的登录Ip不在允许的范围"); // } // BaseEmployee oEmployee = null; // CacheEmployee oCacheEmployee = new CacheEmployee(); // oEmployee = oCacheEmployee.GetEmployee(this.iUserId); // //CachePurviewPage oCachePurviewPage = new CachePurviewPage(); // //List<BasePurviewPage> listPurview = oCachePurviewPage.GetAllPage(); // //BasePurviewPage purviewPage = null; // //foreach (BasePurviewPage purview in listPurview) // //{ // // if (purview.PageUrl.ToLower() == thisPageUrl) // // { // // purviewPage = purview; // // } // //} // //if (purviewPage != null) // //{ // // if (!purviewPage.IsSetToGroup(oEmployee.MainGroupId)) // // { // // this.LoginError("你没有访问该页面的权限"); // // } // //} //} //oBaseLog.SaveLog(LogVisit.AddLogToDB(E_Request, iUserId, oBaseLog.GetRealIP())); }