过滤器中获取form表单或url请求数据

 
            var httpFormData = filterContext.HttpContext.Request.Form;
            var logContent = string.Empty;
    
          //获取url的
            logContent = filterContext.HttpContext.Request.QueryString.ToString();
        //获取表单的
            if (httpFormData.Count > 0)
            {
                try
                {
                    var formDataList = (from f in httpFormData.AllKeys
                                        select new
                                        {
                                            name = m,
                                            value = httpFormData[m]
                                        }).ToList();

                    logContent = string.Join(",", formDataList);
                }
                catch (Exception ef)
                {
                    logContent = filterContext.HttpContext.Server.HtmlEncode(ef.ToString());
                }
            }    

  

posted @ 2018-04-24 15:57 有文有武? 阅读(...) 评论(...) 编辑 收藏