/// <summary> Retrieves a HTTP header, given a predefined header name from the HttpHeaderFields enumeration. </summary> /// <remarks> ebrown, 2/10/2011. </remarks> /// <exception cref="ArgumentNullException"> Thrown when the given request is null. </exception> /// <exception cref="ArgumentException"> Thrown when the enumeration value passed is not defined or is some sort of bitmask. </exception> /// <param name="request"> The request. </param> /// <param name="headerName"> Name of the header. Bitmasks are not accepted. </param> /// <returns> The value stored in the given header with any "s totally removed, or string.Empty if null / missing / empty / whitespace. </returns> public static string RetrieveHeader(this HttpRequestBase request, HttpHeaderFields headerName) { if (null == request) { throw new ArgumentNullException("request"); } if (!Enum.IsDefined(typeof(HttpHeaderFields), headerName)) { throw new ArgumentException("passed enumeration value must be a defined value and cannot be a mask"); } string returnHeader = request.Headers[headerName.ToEnumValueString()]; if (string.IsNullOrWhiteSpace(returnHeader)) { return(string.Empty); } return(returnHeader.Replace("\"", string.Empty)); }
/// <summary> Retrieves a HTTP header, given a predefined header name from the HttpHeaderFields enumeration. </summary> /// <remarks> ebrown, 2/10/2011. </remarks> /// <exception cref="ArgumentNullException"> Thrown when the given request is null. </exception> /// <exception cref="ArgumentException"> Thrown when the enumeration value passed is not defined or is some sort of bitmask. </exception> /// <param name="request"> The request. </param> /// <param name="headerName"> Name of the header. Bitmasks are not accepted. </param> /// <returns> The value stored in the given header with any "s totally removed, or string.Empty if null / missing / empty / whitespace. </returns> public static string RetrieveHeader(this HttpRequestBase request, HttpHeaderFields headerName) { if (null == request) { throw new ArgumentNullException("request"); } if (!Enum.IsDefined(typeof(HttpHeaderFields), headerName)) { throw new ArgumentException("passed enumeration value must be a defined value and cannot be a mask"); } string returnHeader = request.Headers[headerName.ToEnumValueString()]; if (string.IsNullOrWhiteSpace(returnHeader)) return string.Empty; return returnHeader.Replace("\"", string.Empty); }