HttpModule 的权限管理

作者:互联网   出处:控件中国网   2014-11-05 19:04:50   阅读:1

HttpModule 的权限管理
 
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

/// <summary>
///Class1 的摘要说明
namespace MyModule
{
    public class MyModule : IHttpModule
    {
        /// <summary>
        /// 初始化加入两个事件到Application 里面去.
        /// </summary>
        /// <param name="application"></param>
        public void Init(HttpApplication application) 
        {
            application.BeginRequest += (new
            EventHandler(this.Application_BeginRequest));
            application.EndRequest += (new
            EventHandler(this.Application_EndRequest));
        }
        ///在这里必须相当于是把Response转过来。在这里根本直接用不了。不知道为啥。
        ///写这个的作用是进行权限判断。
        private void Application_BeginRequest(Object source, EventArgs e) 
        {
            HttpApplication Application = (HttpApplication)source;
            HttpResponse ResponseOK = Application.Context.Response;


           
           
            ResponseOK.Write("<h1>Beginning of Request</h1><hr>");
           
        }
        private void Application_EndRequest(Object source, EventArgs e)
        {
            HttpApplication Application = (HttpApplication)source;
            HttpResponse ResponseOK = Application.Context.Response;
            ResponseOK.Write("<h1>End of Request</h1><hr>");
        }
        public void Dispose() { }
    }
}

////下面是Web.Config 里面的

  <httpModules>
   <add name="ScriptModule" type="System.Web.Handlers.ScriptModule,
System.Web.Extensions, Version=3.5.0.0, Culture=neutral,
PublicKeyToken=31BF3856AD364E35"/>
   <add name="MyModule" type="MyModule.MyModule"/>
   <!--<add name="MyModule" type=""/>-->
  </httpModules>
///这样每执行个页面会调用这个方法。

 

Copyright© 2006-2015 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 渝ICP备12000264号 法律顾问:元炳律师事务所
客服软件
live chat