首先,你要建立一个类库的项目
然后呢,你就按照上图所示去写代码吧,记住,必须要实现两个方法Dispose()和Init();
好吧,你懒,给你代码,复制一下吧,呵呵。
public void Dispose()
{
}
public void Init(HttpApplication context)
{
context.BeginRequest += new EventHandler(Application_BeginRequest);
}
public void Application_BeginRequest(object sender, EventArgs e)
{
HttpApplication application = sender as HttpApplication;
HttpContext context = application.Context;
HttpResponse response = context.Response;
response.Write("这是来自自定义HttpModule中有BeginRequest ssssssss");
}
然后你就可以生产解决方案了,要把生产过的bin目录下的.dll文件放到iis的bin目录里
SharePoint 2010 默认将所有的 httpModule 配置在 IIS7 专有的system.webServer/modules节中。(dll在bin目录)
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="HttpModuleDemo" type="HttpModuleDemo.HttpModuleDemo,HttpModuleDemo"/>
</modules>
并在<system.web>节点下添加
<system.web>
<httpModules>
<add name="HttpModuleDemo" type="HttpModuleDemo.HttpModuleDemo,HttpModuleDemo" />
</httpModules>
ok