ASP.Net/Network/IHttpModule

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

Implements IHttpModule

using System;
using System.Web;

namespace MyLib {
    class SimpleModule : IHttpModule {
        public void Init(HttpApplication application) {
            application.BeginRequest += new
                EventHandler(this.Application_BeginRequest);
        }
        public void Dispose() {
        }
        public void Application_BeginRequest(object source, EventArgs e) {
            HttpApplication application = (HttpApplication)source;
            application.Context.Response.Write("a module can end the request");
            application.Context.Response.End();
        }
    }
}
BuildSimpleModule.bat
csc /target:library /reference:System.Web.dll 
/out:MyLib.dll SimpleModule.cs
ModuleWeb.config
<configuration>
    <system.web>
        <httpModules>
            <add name="SimpleModule" 
                 type="MyLib.SimpleModule, 
                       MyLib" />
        </httpModules>
    </system.web>
</configuration>