locked
httpModule in Web Application Project not being called RRS feed

  • Question

  • User1254222884 posted

    I'm working on moving our website project to a web application project and have run into a problem with httpModule.

    I cannot get an httpModule to be run when running the compiled web application project in IIS. When I run it in IIS Express in Visual Studio (2019 16.9.2), it is called. But when I change to Local IIS, the httpModule init method is never called.

    To duplicate:

    1. Create a new Visual Studio project
    2. ASP.NET Web Application (.NET Framework) template
    3. Project Name: ModuleTest, place solution and project in the same directory
    4. Create
    5. Web Froms and Web API
    6. Create
    7. Add new folder: AppCode
    8. Add new subfolder httpModule
    9. Add new item in httpModule subfolder
    10. select ASP.NET Module
    11. Name: TestModule.cs
    12. Add
    13. Put a breakpoint on line 24 (context.LogRequest += new EventHandler(OnLogRequest);)
    14. Add the following code to the web.config file just before the </system.webServer> closing tag:

    ```
         <modules>
            <add name="TestModule" type=" ModuleTest.AppCode.httpModule.TestModule"/>
         </modules>
    ```

    • Run the debugger and note that the debugger stops in the httpModule at the breakpoint.
    • Now, change the debug setting to use Local IIS (instead of IIS Express)
    • Create Virtual Directory
    • Verify that the virtual directory/application is using an integrated application pool
    • Run the debugger and note that the debugger DOES NOT stop in the httpModule at the breakpoint.

    How do I get the httpModule to execute in the Local IIS context?

    Thursday, March 18, 2021 7:21 PM

Answers

  • User1254222884 posted

    No, I meant <modules>

    I was looking at code in an aspx.cs code-behind file that was actually outputting data that showed that the httpModule was not being called.

    The solution was in the way the httpModule is specified (different, slightly than in a website project).

    In a website project, I can specify the httpModule with:

    <add name="somename" type="namespace.class" />

    But, in a web application project, you have to specify the FILENAME of the dll the httpModule is in like this:

    <add name="somename" type="namespace.class, filename" />

    This was the key to getting this to work in a web application project.

    Oh, and I'm using Visual Studio 2019, latest build.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 4, 2021 3:55 PM

All replies

  • User753101303 posted

    Hi,

    You meant <httpModules>? A breakpoint outside of the module? I would start by using some actual outcome (adding a http header or whatever) to make 100% if the module is not called or if it"s a debugging problem.

    Edit: which IIS version do you use?

    Tuesday, May 4, 2021 3:35 PM
  • User1254222884 posted

    No, I meant <modules>

    I was looking at code in an aspx.cs code-behind file that was actually outputting data that showed that the httpModule was not being called.

    The solution was in the way the httpModule is specified (different, slightly than in a website project).

    In a website project, I can specify the httpModule with:

    <add name="somename" type="namespace.class" />

    But, in a web application project, you have to specify the FILENAME of the dll the httpModule is in like this:

    <add name="somename" type="namespace.class, filename" />

    This was the key to getting this to work in a web application project.

    Oh, and I'm using Visual Studio 2019, latest build.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 4, 2021 3:55 PM