在Global.asax文件的Application_BeginRequest中获取request请求内容
protected void Application_BeginRequest(object sender, EventArgs e)
{
try
{
string isLogRequest = System.Configuration.ConfigurationManager.AppSettings["IsLogRequest"];
if (isLogRequest.Trim() == "false")
{
return;
}
//遍历Post参数
foreach (string key in Request.Form.AllKeys)
{
if (key == "__VIEWSTATE" || key == "__VIEWSTATEGENERATOR" || key == "__EVENTVALIDATION")
{
continue;
}
log.Info(key + ":" + Request.Form[key].ToString());
}
//遍历Get参数。
foreach (string key in this.Request.QueryString.AllKeys)
{
log.Info(key + ":" + Request.QueryString[key].ToString());
}
}
catch (Exception ex)
{
log.Error(ex.StackTrace);
}
}