C# 获取请求头中包含指定元素的值

扩展方法

 public static string HeaderValue(this HttpRequest request,string headerKey)
        {
            if (request != null)
            {
                var dict = request.Headers;

                if (dict.ContainsKey(headerKey))
                {
                    var val =  dict[headerKey];
                    if (!String.IsNullOrEmpty(val))
                    {
                        return val;
                    }
                }
            }
            return "";
        }

使用:

posted @ 2021-05-11 18:05  清和时光  阅读(1627)  评论(0编辑  收藏  举报