ASP.NET页面生命周期之HttpMoudle

namespace TestForWeb
{
    public class MyModule : IHttpModule
    {
        public void Dispose()
        {

        }

        public void Init(HttpApplication applcation)
        {
            applcation.BeginRequest += new EventHandler(Application_BeginRequest);
            applcation.EndRequest += (sender, e) => { applcation.Context.Response.Write("1"); };
            applcation.PreSendRequestHeaders += (sender, e) => { applcation.Context.Response.Write("2"); };
            applcation.PreSendRequestContent += (sender, e) => { applcation.Context.Response.Write("3"); };
        }

        public void Application_BeginRequest(object sender, EventArgs e)
        {
            HttpApplication ha = sender as HttpApplication;
          //  ha.CompleteRequest();
            ha.Context.Response.ContentType = "text/plain";
            ha.Context.Response.ContentEncoding=System.Text.Encoding.GetEncoding("GBK");
            ha.Context.Response.Write("请求已终止");
        }
    }
 
}
<system.webServer>
    <modules>
      <add name="MyModule" type="TestForWeb.MyModule,TestForWeb" />
    </modules>
    <handlers>
      <add name="MyHandlerFactory" path="*.ds" verb="*" type="TestForWeb.MyHandlerFactory,TestForWeb"  />
    </handlers>
  </system.webServer>

 

posted on 2017-05-05 16:06  奔游浪子  阅读(78)  评论(0)    收藏  举报

导航