Eng Boon
Eng Boon

Reputation: 363

mvc 4 web api add custom response http header

Can we add the extra http response header item example "Last Updated" beside the default response header?

example when I call (Request):
localHost:12345/API/GetInfo
with header:
Host: localHost:12345
......


then the api will reply the header with(Response):
HTTP/1.1 200 OK
Content-Length: XX
Content-Type: XXX
Last-Update: The value and the value generate from the API function

Upvotes: 12

Views: 26748

Answers (4)

Tola Ch.
Tola Ch.

Reputation: 198

I just found a solution. What I need to do is, response HTTP header in cookie format. That way, browser will always return it back to my web server.

Upvotes: 0

TapiwaJoel Mudavanhu
TapiwaJoel Mudavanhu

Reputation: 53

In MVC 5 just add

 Response.AppendHeader("header", "value");

Upvotes: 0

JTech
JTech

Reputation: 3570

FYI there is an official HTTP Header that you can use to represent the DateTime a resource was last updated.

It is the 'Last-Modified' Header (See section 14.29 on Section 14 page of the specification).

You add it to your response like this:

Response.Content.Headers.LastModified = yourResource.LastUpdatedDateTime;

Upvotes: 9

HoberMellow
HoberMellow

Reputation: 8558

You can add header by using this code:

HttpContext.Current.Response.AppendHeader("Last-Update", value);

Upvotes: 26

Related Questions