I can't return Content-Ranger Response Header from my ASP.NET Web API

Sheikh Abdullah 1 Reputation point

I am making Admin Dashboard using React-Admin Library of React. This library requires Content-Range Header in Response from server. So, I modified my ASP.NET API Controller:

public HttpResponseMessage GetUSERS()
            IQueryable<USER> data = db.USERS;

            HttpResponseMessage resp = Request.CreateResponse(HttpStatusCode.OK, data);
            resp.Headers.Add("Access-Control-Expose-Headers", "Content-Range");
            resp.Headers.Add("Content-Range", "users 0-3/3");
            return resp;

Before modification the usual JSON response was:

[{"user_id":1,"user_fname":"value","user_lname":"value","user_email":"value","user_password":"value"},{"user_id":2,"user_fname":"value","user_lname":"value","user_email":"value","user_password":"value"},{"user_id":3,"user_fname":"value","user_lname":"value","user_email":"value","user_password":"value"} ]

But then I get this exception when I add

resp.Headers.Add("Content-Range", "users 0-3/3");


ExceptionMessage: "Misused header name. Make sure request headers are used with HttpRequestMessage, response headers with HttpResponseMessage, and content headers with HttpContent objects."

I have tried replacing Content-Range value with "bytes 0-3/3", "bytes 1-3/3", "0-3/3" etc. But all produced the same error.

A set of technologies in the .NET Framework for building web applications and XML web services.
3,181 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 52,591 Reputation points

    Because it’s a content header, not a request header. Use resp.Content.Headers

    0 comments No comments