欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2022-04-27 23:37:50
var httpFormData = filterContext.HttpContext.Request.Form; var logContent = string.Empty; //获取url的 logContent = filterContext.HttpContext.Request.... ......
 
            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());
                }
            }