In. Net, we may need to modify our header packets for security or other reasons.
In the following method, we use the HTTP Module to remove or modify it programmatically.
First, we define a class CustomServerHeaderModule that inherits from IHttpModule and creates an event handler for the PreSendRequestHeaders event.
The Code is as follows:
Using System; using System. collections. generic; using System. linq; using System. web; namespace Cloud. apiWeb. models {public class CustomServerHeaderModule: IHttpModule {public void Init (HttpApplication context) {context. preSendRequestHeaders + = OnPreSendRequestHeaders;} public void Dispose () {} void OnPreSendRequestHeaders (object sender, EventArgs e) {// remove the Server header // HttpContext. current. response. headers. remove ("Server"); // reset the Server header HttpContext. current. response. headers. set ("Server", "Windows Server 2012 ");}}}