How can I register a common class as an IHttpModule

public class NHibernateSessionPerRequest<T>:IHttpModule
{
    public void Dispose() { }

    public void Init(HttpApplication context)
    {
        context.BeginRequest += BeginRequest;
        context.EndRequest += EndRequest;
    }
}

How can it be registered in web.config?

+3
source share
2 answers

IIS6: In the system.web section of your web.config

<configuration>
  <system.web>
    <httpModules>
      <add name="MyModule" type="My.Namespace.NHibernateSessionPerRequest`1[[My.Namespace.MyType, My.Assembly]], My.Assembly"/>
    </httpModules>
  </system.web>
</configuration>

IIS7: In the system.webserver section of your web.config:

<configuration>
  <system.webServer>
    <modules>
      <add name="MyModule" type="My.Namespace.NHibernateSessionPerRequest`1[[My.Namespace.MyType, My.Assembly]], My.Assembly"/>
    </modules>
  </system.webServer>
</configuration>

For both, replace "My.Namespace" with the class namespace and "My.Assembly" with the name of the assembly.

+4
source

The simplest solution is to create a specific type that comes from that type, and then register this:

public class MyActualModule : NHibernateSessionPerRequest<SomeType> {
}

Then in web.config register MyActualModule.

, CLR, , , . , , , , , 100 .

+2

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


All Articles