I'm developing sharepoint 2010 web appliation. I want to handle some Applicaton events (Begin_Request, End_Request, Application_Start) in manner of classic asp.net way through the using Global.asax inherited from SPHttpApplication.
I found two way to distinguish that.
The first one suggests to overload SPHttpApplication in Global class. Good idea but not suitable for me because my application is deployed to sub-site of another main site. If there is a way to get around this moment it would be a great solution!
The second one suggests to implement IHttpModule interface and register events from HttpApplication context variable. It is suitable for me and I created class library project with one class implementing this interface. I've also add special record in my web.config file:
<httpModules>
<add name="DSModule" type="Artec.DS.HttpContext.DSModule, DSModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31a3567341f39f94"/>
</httpModules>
where 'Artec.DS.HttpContext' is a project name and DSModule is a class name. And after all when I'm starting debug, 'Init()' method is not called.
UPDATE
namespace Artec.DS.HttpContext
{
public class DSModule : IHttpModule
{
public void Dispose()
{
throw new NotImplementedException();
}
public void Init(HttpApplication context)
{
System.Diagnostics.Debugger.Launch();
ApplicationVariables.AppPath = context.Server.MapPath("/");
NhibernateManager.Init();
NavigationManager.Init();
}
}
}
First of all my web.config has wrong "type" attribute. I was confused with class name instead of assembly name. So well-formed tag is as follow:
<add name="DSModule" type="Artec.DS.HttpContext.DSModule, Artec.DS.HttpContext, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31a3567341f39f94" />
After modification of web.config system.webServer/modules (thanks to CBono) Init() was called and this is an answer on my initial question.
But now I get error: "System.Web.HttpException: Server operation is not available in this context." when trying to map server path:
context.Server.MapPath("/")
The web.config entry you have listed is appropriate if your IIS instance is version 6, or if you're running in version 7 Classic Mode.
Try also adding this to your web.config to cover IIS 7 Integrated Mode (which you're probably using):
<configuration>
<system.webServer>
<modules>
<add name="DSModule" type="Artec.DS.HttpContext.DSModule, DSModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31a3567341f39f94"/>
</modules>
</system.webServer>
</configuration>
It's perfectly okay to have your HTTP Module registered in both sections.