My custom httpModule is not detectable using MVC

I created a custom module:

namespace KittenFarm.ServerModules { public class CustomServerHeaderModule : IHttpModule { public void Init(HttpApplication context) { context.PreSendRequestHeaders += OnPreSendRequestHeaders; } public void Dispose() { } void OnPreSendRequestHeaders(object sender, EventArgs e) { HttpContext.Current.Response.Headers.Remove("Server"); } } } 

And I registered it in my web config:

 <system.webServer> <validation validateIntegratedModeConfiguration="false"/> <modules runAllManagedModulesForAllRequests="true"> <add name="CustomServerHeader" type="CustomServerHeaderModule" /> </modules> .... 

However, it never starts.

I suspected it was a namespace problem, but I tried every combination of namespaces in the type= section that I can think of, and it never hits the breakpoint that I inserted into it.

Any ideas?

+4
source share
3 answers

The problem was that the solution was configured to use Visual Studio Development Server, which does not pick up http modules. After I changed it to use my local IIS, it worked.

+1
source

You are correct, this is your namespace is not in the type.

The following worked for me:

  <modules runAllManagedModulesForAllRequests="true"> <add name="CustomServerHeader" type="KittenFarm.ServerModules.CustomServerHeaderModule" /> </modules> 
+4
source

You can configure the function to run before calling the Application_Start method. Add below code to global.asax

[assembly: PreApplicationStartMethod (TypeOf (CS.MVCHttpModule.MvcApplication), "Register")]

See http://dotnetlionet.blogspot.in/2015_06_01_archive.html

0
source

Source: https://habr.com/ru/post/1488672/


All Articles