在 Global.asax中:
protected void Application_BeginRequest(object sender, EventArgs e) { Common.Log log = new Common.Log(); try { if (bool.Parse(ConfigurationManager.AppSettings["request_log"])) { if (this.Request != null && this.Request.Form != null && this.Request.Form.AllKeys.Length > 0) { StringBuilder requestParam = new StringBuilder(this.Request.Url.AbsoluteUri + " "); foreach (var item in this.Request.Form.AllKeys) { requestParam.AppendFormat("{0}={1}&", item, this.Request.Form[item]); } log.addLog(string.Format("【{0}】{1}", this.Request.UserHostAddress, requestParam.ToString().Remove(requestParam.Length - 1, 1))); } } } catch (Exception ex) { log.addLog(ex); } }