Click here to Skip to main content
14,665,426 members
Rate this:
Please Sign up or sign in to vote.
See more:
how to disable the sending of http header data in api response.

like fallowing headers in web api 2

Cache-Control →no-cache
Connection →close
Content-Length →20
Content-Type →application/json; charset=utf-8
Date →Mon, 12 Jun 2017 10:06:04 GMT
Expires →-1
Pragma →no-cache
Server →Microsoft-IIS/8.5
X-AspNet-Version →4.0.30319

What I have tried:

i have tried adding fallowing code in global.asax
protected void Application_PreSendRequestHeaders()


and from iis http response header i have removed X powered by

with above procedure i am able to disable
X powered by
headers but
I am unable to delete remaining header those are
Cache-Control →no-cache
Content-Length →7
Content-Type →application/json; charset=utf-8
Date →Sun, 25 Jun 2017 12:15:41 GMT
Expires →-1
Pragma →no-cache
.Even i Have tried with uriscan tool also.
Any help could be appreicated.
Updated 26-Jun-17 5:37am

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Simple: You don't.

Those headers are part of the HTTP grammar. If you removed them, your response would no longer be valid.

Hypertext Transfer Protocol - Wikipedia[^]
List of HTTP header fields - Wikipedia[^]

You can change the Cache-Control, Expires and Pragma headers by setting the CacheControl[^] property on the response.

The Content-Type and Content-Length headers will be set by the response formatter. They cannot be changed or removed, since that would break the response.

The Date is set automatically, and cannot be changed or removed.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100