Created
June 19, 2012 12:12
-
-
Save tugberkugurlu/2953810 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class WebApiApplication : System.Web.HttpApplication { | |
protected void Application_Start() { | |
//... | |
GlobalConfiguration.Configuration.MessageHandlers.Add(new RemoveServerHeaderMessageHandler()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RemoveServerHeaderMessageHandler : DelegatingHandler { | |
protected override System.Threading.Tasks.Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) { | |
return base.SendAsync(request, cancellationToken).ContinueWith(task => { | |
var response = task.Result; | |
var httpContext = response.RequestMessage.Properties["MS_HttpContext"] as HttpContextWrapper; | |
if (httpContext != null) | |
httpContext.Response.Headers.Remove("Server"); | |
return response; | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment