views:

297

answers:

2

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.

+3  A: 

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.

Mitchel Sellers
Sorry about my ignorance in this, but do I need to explicitly compile the cs file into a dll in order to regsiter it in web.config?
Praesagus
It can be part of the web project, you just have to know the name of the compiled assembly.
Mitchel Sellers
How would I go about finding that, and then what would I enter as my regsitration?
Praesagus
The dll name is the assembly name, in the project properties for the project file.
Mitchel Sellers
A: 

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
Praesagus