Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

registering httpModules in web.config

Tags:

c#

asp.net

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.

like image 980
Praesagus Avatar asked Sep 18 '09 18:09

Praesagus


People also ask

Where do I put modules in web config?

In the Connections pane, expand the server name, expand Sites, and then go to the Web site or application to which you want to add a managed module. In the Home pane, double-click Modules. In the Actions pane, click Add Managed Module.

What are Httpmodules?

An HTTP module is an assembly that is called on every request that is made to your application. HTTP modules are called as part of the ASP.NET request pipeline and have access to life-cycle events throughout the request. HTTP modules let you examine incoming and outgoing requests and take action based on the request.

What is HTTPHandlers and Httpmodules?

HTTP modules and HTTP handlers are an integral part of the ASP.NET architecture. While a request is being processed, each request is processed by multiple HTTP modules (for example, the authentication module and the session module) and is then processed by a single HTTP handler.

What is HTTP handler in MVC?

HTTPHandlers. ASP.Net HTTPHandler is a process that runs in response to a request made to an ASP.Net application. When a client makes a request to a server resource, each request is handled by HTTPHandler based on the request file extension (. aspx, . asmx etc).


2 Answers

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 
like image 105
Praesagus Avatar answered Oct 17 '22 12:10

Praesagus


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> 
like image 36
Rishi Avatar answered Oct 17 '22 12:10

Rishi