1
votes

I want to remove http response header in mvc.

HTTP/1.1 404 Not Found Cache-Control: private Content-Type: text/html; charst=utf-8 Server: Microsoft-IIS/8.0 X-Powered-By: ASP.NET Date: Mon, 23 Feb 2015 12:43:58 GMT Content-Length: 4898 Connection: Keep-Alive

I remove Connection, X-Powered-By, Server, Cache-Control with this code:

> protected void Application_PreSendRequestHeaders(object sender,EventArgs e)
> {
> HttpContext.Current.Response.Headers.Remove("X-Powered-By");
> HttpContext.Current.Response.Headers.Remove("X-AspNet-Version");
> HttpContext.Current.Response.Headers.Remove("X-AspNetMvc-Version");
> HttpContext.Current.Response.Headers.Remove("Server");
> HttpContext.Current.Response.Headers.Remove("Cache-Control");
> }

but how can i do remove all http response header?

1
i can not remove Date, HTTP, Content-Type, Content-Length. please help me.mahdis dezfouli
See comment on this (not so good) answer, your remove code may lead to server freezes.Frédéric

1 Answers

0
votes

Please update your question with more information on the reasons driving you to remove those headers, since this looks to me as a quite unusual need, especially for content-type. It may turn out you need to do something else.

Otherwise, read on.

Try with IISRewrite module. It should allow you to get them blank. See this answer or this more detailed one.

If removing them is really what you require, you may have to write your own custom isapi filter. There is some information about this solution on this other answer.

For many of them, you may also consider disabling what adds them rather than removing them after they have been added. See my answer on this subject for a bunch of them.