zoukankan      html  css  js  c++  java
  • HttpModule的简单示例

    1.HttpModule可用在asp.net 管线事件触发的过程中。。 可处理一些通用的操作,如给特定请求加 gzip压缩。

    2.示例代码:

    using System;
    using System.Web;
    
    namespace MyWebApp
    {
        public class MyHttpModule : IHttpModule
        {
            public void Init(HttpApplication application)
            {
                application.BeginRequest += new EventHandler(application_BeginRequest);
            }
    
            public void application_BeginRequest(object sender, EventArgs e)
            {
                HttpContext context = (sender as HttpApplication).Context;
                context.Response.Write("这一部分是由HttpModule添加!<br><script>alert('测试脚本标签')</script>");
            }
    
            #region IHttpModule 成员
    
            void IHttpModule.Dispose()
            {
                throw new NotImplementedException();
            }
    
            #endregion
        }
    }

    3.要使 HttpModule生效。还需要配置web.config。

    <system.webServer>
    <
    modules> <remove name="MyHttpModule"/> <add name="MyHttpModule" type="MyWebApp.MyHttpModule"/> </modules>
    </system.webServer>
     
  • 相关阅读:
    HelpersRainCaptcha
    HelpersPHPMailer
    HelpersPassword
    HelpersPagination
    HelpersNumber
    HelpersHooks
    HelpersGeoCode
    HelpersFastCache
    HelpersDocument
    eclipse 设置jsp页面为HTML5
  • 原文地址:https://www.cnblogs.com/gaocong/p/6734556.html
Copyright © 2011-2022 走看看