码迷,mamicode.com
首页 > Web开发 > 详细

asp.net webform过滤器

时间:2016-09-30 14:44:54      阅读:353      评论:0      收藏:0      [点我收藏+]

标签:

1.
  public class PageFilter : IHttpModule
    {
        public String ModuleName
        {
            get { return "PageFilter"; }
        }

        public void Dispose()
        {
            
        }

        //在 Init 方法中注册HttpApplication 
        // 通过委托方式注册事件
        public void Init(HttpApplication application)
        {
            application.AcquireRequestState += new EventHandler(Application_AcquireRequestState);
        }
        private void Application_AcquireRequestState(Object source, EventArgs e)
        {
            try
            {
                HttpApplication application = (HttpApplication)source;
                HttpContext context = application.Context;
                HttpSessionState session = context.Session;
                HttpRequest request = context.Request;
                HttpResponse response = context.Response;
                String contextPath = request.ApplicationPath;
                if (application.Context.Handler is System.Web.UI.TemplateControl)
                {
                    var path = ((System.Web.UI.TemplateControl)application.Context.Handler).AppRelativeVirtualPath;
                }
            }
            catch (Exception ex)
            {

                throw;
            }
        }
    }
2.web.config
  <system.web>
    <httpModules>
      <add name="pageModule" type="HraWeb.PageFilter,HraWeb"/>
</httpModules>
</system.web>
<system.webserver>
  <add name="pageModule" type="HraWeb.PageFilter,HraWeb"/>
</system.webserver>

 

asp.net webform过滤器

标签:

原文地址:http://www.cnblogs.com/kexb/p/5923359.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!