我创建了一个HttpModule:
using System;
using System.Web;
public class TestModule : IHttpModule
{
public TestModule() { }
public String ModuleName { get { return "TestModule"; } }
public void Dispose() { }
public void Init(HttpApplication app)
{
app.BeginRequest += (new EventHandler(this.DoBeginRequest));
}
private void DoBeginRequest(Object source, EventArgs e)
{
HttpApplication application = (HttpApplication)source;
HttpContext context = application.Context;
context.Response.Write("<pre>Request URL: " + context.Request.FilePath + "</pre>");
context.Response.Flush();
System.Diagnostics.Debug.WriteLine(context.Request.ToString());
}
}
Run Code Online (Sandbox Code Playgroud)
其加载方式如下:
<system.webServer>
<modules>
<add name="TestModule" type="TestModule"/>
</modules>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)
当我从 Web 浏览器或从 调用此函数时 …