Pipeline Pipeline - 1 year ago 156
AngularJS Question

Get a custom header in angular $http from web api controller

I am trying to pass a piece of information along with my content in my HttpResponseMessage like:

string jsonFiles = JsonConvert.SerializeObject(listFiles);
HttpResponseMessage response = new HttpResponseMessage
StatusCode = HttpStatusCode.OK,
Content = new StringContent(jsonFiles)
response.Headers.Add("Key", "Value");

return response;

However in my angular call and response I cannot see the "Key" header in response.config.headers or response.headers. Any idea why?

$http.get("/api/Locker").then(function (response) {

In my Startup.cs I do have:


Answer Source

As per the documentation response.config returns the config used while sending the request. response.headers is a function. Try using response.headers("Key") and see if it helps.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download