過濾器中獲取form表單或url請求資料

有文有武?發表於2018-04-24
 
            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());
                }
            }    

  

相關文章