12

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

4 Answers 4

26

You can add header by using this code:

HttpContext.Current.Response.AppendHeader("Last-Update", value);
Sign up to request clarification or add additional context in comments.

8 Comments

thanks bro. I Modified to HttpContext.Current.Response.AppendHeader("Last-Update", value);
Oh, sorry, my mistake. I fixed my answer. You're weclome)
Any way of doing it without using System.Web.HttpContext?
This is not encouraged, self hosting means HttpContext.Current is not available, so this will not always work.
I got another problem: when Browser perform next request. it does not not include the header "Last-Update" back to server. How to make browser return all headers from its prior response?
|
9

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;

1 Comment

Sorry, I'm looking for custom response header(it can be other beside date), your answer was standard response header.
0

In MVC 5 just add

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

Comments

0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.