public void OnException(ExceptionContext filterContext) { filterContext.ExceptionHandled = true; var ex = filterContext.Exception; string controller = filterContext.RouteData.Values["controller"].ToString(); string action = filterContext.RouteData.Values["action"].ToString(); #region 日志记录 string logPath = filterContext.HttpContext.Server.MapPath("~/Log/") + "ErrorHandle_" + DateTime.Now.ToString("yyMMddHH") + ".txt"; string _logStr = string.Format("控制器:{0}\r\n处理函数:{1}\r\n异常信息:{2}", controller, action, ex.ToString()); Toolkits.WriteLog(logPath, _logStr); #endregion throw new HttpException(500, _logStr); //filterContext.Result = new RedirectResult(string.Format("/Home/ErrorHandler?controllername={0}&actionname={1}&exMessage={2}", controller, action, HttpUtility.UrlEncode(ex.Message))); }
public static byte[] GetPO(string server, int PurchaseOrderID) { HttpWebRequest _request = null; HttpWebResponse _response = null; string acc = ConfigurationManager.AppSettings["ServerAcc"].ToString(); string pwd = ConfigurationManager.AppSettings["ServerPwd"].ToString(); NetworkCredential _cred = new NetworkCredential(acc, pwd); //NetworkCredential _cred = CredentialCache.DefaultNetworkCredentials; //Uri uri = new Uri(server); //ICredentials credentials = CredentialCache.DefaultNetworkCredentials; //NetworkCredential _cred = credentials.GetCredential(uri, "Basic"); string content = ""; try { _request = (HttpWebRequest)WebRequest.Create(server + "/Purchase/PRForm?PurchaseOrderID=" + PurchaseOrderID); _request.PreAuthenticate = true; _request.Credentials = _cred; _request.Timeout = 10000; _request.AllowAutoRedirect = false; _response = (HttpWebResponse)_request.GetResponse(); if (_response.ToString() != "") { Stream streamReceive = _response.GetResponseStream(); Encoding encoding = Encoding.GetEncoding("UTF-8");//乱码处理 StreamReader streamReader = new StreamReader(streamReceive, encoding); content = streamReader.ReadToEnd(); } } catch (Exception ex) { string WebLogPath = HttpContext.Current.Server.MapPath("~/Log/"); if (!Directory.Exists(WebLogPath)) { DirectoryInfo dir = new DirectoryInfo(WebLogPath); dir.Create(); } string logPath = WebLogPath + "PO(PDF)生成_" + PurchaseOrderID.ToString() + "_" + DateTime.Now.ToString("yyMMddHHmm") + ".txt"; Toolkits.WriteLog(logPath, "用户名:" + _cred.UserName + ";密码:" + _cred.Password + "\r\n" + ex.Message.ToString()); content = ""; } return(Html2PDF(content, "PO")); }
public void LogRecord(string filename, string content) { string logPath = Server.MapPath("~/Log/") + filename + "_" + DateTime.Now.ToString("yyMMddHH") + ".txt"; Toolkits.WriteLog(logPath, content); }