registering httpModules in web.config

I am trying to register a custom HttpHandler in the web.config file. MSDN’s example shows an entry that is commented out…um which doesn’t work so well. When I uncomment I receive a Could not load file or assembly 'HttpModule.cs' or one of its dependencies. The system cannot find the file specified. error. The file name is HttpModule.cs and the class name is MyHttpModule. There is no explicit namespace yet.

<httpModules>
     <add name="MyHttpModule" type="MyHttpModule, HttpModule" />
<httpModules>

I am sure I am overlooking the obvious. Do I need to specify the file path somewhere? Thanks in advance.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

I am still learning much of the terminology and needed it spelled out for me. In case any of you need the same…

As an example if:

  • The base class name and project name is TestSite
  • The namespace my class is in is BusinessLogic
  • The class name is PageAuthorization

in the Web.config file…

<configuration> 
 <system.web> 
  <httpModules> 
   <add type= "BusinessLogic.PageAuthorization, TestSite" name="PageAuthorization" /> 
  </httpModules> 
 </system.web> 
</configuration>

In my case I had to mark my class with IHttpModule. The definition of the class would look like:

public class PageAuthorization : IHttpModule

Method 2

If you are loading Custom module from .Net 4.0 GAC and IIS 6/7 classic mode you have to use below code

 <system.web>
  <httpModules>
  <add name="ClientHttpModule" type="ClientServHttpModule.ClientHttpModule,ClientServHttpModule,Version=1.0.0.0, Culture=neutral, PublicKeyToken=3af8d8e2f9e8b6c3" />
      </httpModules>
 </system.web>

ClientServHttpModule is namespace of your custom module.
Public key token you can get it from sn.exe app.

if you are running in Integrated mode.use below code

<system.webServer>
        <modules>
            <add name="ClientHttpModule" type="ClientServHttpModule.ClientHttpModule,ClientServHttpModule,Version=1.0.0.0, Culture=neutral, PublicKeyToken=3af8d8e2f9e8b6c3" />
        </modules>
    </system.webServer>

Method 3

The type value is in the format of {Class}, {assembly}.

So in your case, it should be MyHttpModule, MyDllName

Where MyDllName is the name of the compiled DLL.

Method 4

Note for people landing here looking for configuration for IIS 7 and above running in Integrated Mode:

<configuration> 
 <system.webServer> 
  <modules> 
   <add type= "BusinessLogic.PageAuthorization, TestSite" name="PageAuthorization" /> 
  </modules> 
 </system.webServer> 
</configuration>

Method 5

To add to this, it is important to be sure that the .dll you are trying to use is in the project bin folder. I had the problem of making my module in a separate project, but forgetting to push over the .dll file.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x