我创建了一个简单的 HttpModule 来记录我现有 Web 服务的使用情况。有一个包含单个类的 dll
public class TrackingModule : System.Web.IHttpModule
{
public TrackingModule(){}
public void Init(System.Web.HttpApplication context)
{
context.BeginRequest+=new EventHandler(context_BeginRequest);
}
public void Dispose()
{
}
private void context_BeginRequest(object sender, EventArgs e)
{
try
{
Microsoft.ApplicationBlocks.ExceptionManagement.ExceptionManager.Publish( new Exception("Log attept") );
HttpApplication app = (HttpApplication)sender;
string method = app.Request.RawUrl;
SaveUseToDatabase( app.Request.UserHostAddress, method );
}
catch( Exception ex )
{
try
{
Microsoft.ApplicationBlocks.ExceptionManagement.ExceptionManager.Publish( ex );
}
catch{}
}
}
}
编译完 dll 后,我将它添加到 webservice 的 bin 文件夹中,并在 webservice 的 web.config 中添加:
<system.web>
<httpModules>
<add name="TrackingModule" type="WebserviceTrackingModule.TrackingModule, WebserviceTrackingModule"/>
这在我的计算机上运行良好,但是当我将其复制到生产服务器时,什么也没有发生。数据库中没有新条目,ExceptionManager 没有记录任何条目。就好像它根本不存在一样。
我能错过什么?
编辑:在执行另一个测试后,我可以添加它在我为拥有自己的顶级虚拟目录的 web 服务添加它时工作。它不适用于驻留在作为另一个虚拟目录的子文件夹的虚拟目录中的 Web 服务。
我知道 HttpModules 设置被子目录继承,但看起来父目录的存在妨碍了。