【发布时间】:2014-03-03 20:14:31
【问题描述】:
我在使用自定义 HTTPModule 类将消息记录到 EventViewer\WindowsLogs 时遇到问题。我已经尝试使用管理员权限运行 Visual Studio,我也尝试从 IIS 6.0 开始。它不会崩溃,只是不添加任何代码。下面是模块类和配置文件。
HttpModule
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Diagnostics;
namespace Chapter_V.HttpModules
{
public class MyHttpModule : IHttpModule
{
public void Init(HttpApplication application)
{
application.AuthenticateRequest += new EventHandler(OnAuthentication);
}
private void OnAuthentication(object sender, EventArgs e)
{
string name = HttpContext.Current.User.Identity.Name;
EventLog log = new EventLog();
log.Source = "My First HttpModule";
log.WriteEntry(name + " was authenticated !");
}
public void Dispose()
{
}
}
}
web.config
<?xml version="1.0"?>
<configuration>
<system.web>
<httpModules>
<add name="MyHttpModule" type="Chapter_V.HttpModules.MyHttpModule,ChapterV"/>
</httpModules>
</system.web>
<system.webServer>
<modules>
<add name="MyHttpModule" type="Chapter_V.HttpModules.MyHttpModule,ChapterV"/>
</modules>
</system.webServer>
</configuration>
您对此问题有任何想法吗? (仅供学习使用)
【问题讨论】:
标签: asp.net httpmodule