How to retrieve HTTP header information from a C# RESTful Service Method

.net, c#, http, rest

Solution

I was able to get what I was looking for using the HttpContext.Current property. Using the Request.Headers property I was able to retrieve a name value list of the header information

    public string MethodRequiringAuthorization()
    {
        HttpContext httpContext = HttpContext.Current;
        NameValueCollection headerList = httpContext.Request.Headers;
        var authorizationField = headerList.Get("Authorization");            
        return "{Message" + ":" + "You-accessed-this-message-with-authorization" + "}";
    }

Problem

I have the following C# RESTful interace. ``` [WebGet(UriTemplate = "requires-authorization", ResponseFormat = WebMessageFormat.Json)] [OperationContract] string MethodRequiringAuthorization(); ``` Which is implemented int the following class ``` public string MethodRequiringAuthorization() { //var authorisazation = HTTP header authorization field return "{Message" + ":" + "You-accessed-this-message-with-authorization" + "}"; } ``` I would like to pass into this method the value of the field "Authorization" in the http header (as described in the commented line). Any ideas how I can retrieve this value

Original source