reference:
http://blog.csdn.net/andyhooo/archive/2007/04/29/1591890.aspx
http://topic.csdn.net/t/20050417/19/3944040.html
http://www.cnblogs.com/fanrsh/archive/2006/05/24/408136.html

页面请求过程:

根据这个流程,网上一般的权限验证在:
Http.Module.AuthorizeRequest
Http.Module.PreRequestHandlerExecute

例如使用前者:

using System;
using System.Web;
using System.Security.Principal;
namespace MyModules
{
    public class CustomModule : IHttpModule
    {
        public CustomModule() { }
        public void Dispose() { }
        public void Init(HttpApplication app)
        {
            //建立安全模块   
            app.AuthenticateRequest += new EventHandler(this.AuthenticateRequest);
        }

private void AuthenticateRequest(object o, EventArgs e)
        {
            HttpApplication app = (HttpApplication)o;
            HttpContext content = (HttpContext)app.Context;

if ((app.Request["userid"] == null) || (app.Request["password"] == null))
            {
                content.Response.Write("未提供必需的参数!!");
                content.Response.End();
            }

string userid = app.Request["userid"].ToString();
            string password = app.Request["password"].ToString();
            string[] strRoles = AuthenticateAndGetRoles(userid, password);
            if ((strRoles == null) || (strRoles.GetLength(0) == 0))
            {
                content.Response.Write("未找到相配的角色!!");
                app.CompleteRequest();
            }
            GenericIdentity objIdentity = new GenericIdentity(userid, "CustomAuthentication");
            content.User = new GenericPrincipal(objIdentity, strRoles);
        }

private string[] AuthenticateAndGetRoles(string r_strUserID, string r_strPassword)
        {
            string[] strRoles = null;
            if ((r_strUserID.Equals("Steve")) && (r_strPassword.Equals("15seconds")))
            {
                strRoles = new String[1];
                strRoles[0] = "Administrator";
            }
            else if ((r_strUserID.Equals("Mansoor")) && (r_strPassword.Equals("mas")))
            {
                strRoles = new string[1];
                strRoles[0] = "User";
            }
            return strRoles;
        }
    }
}

  编辑Web.config文件:   
  <system.web>   
  <httpModules>   
          <add   name="Custom"   type="MyModules.CustomModule,Custom"/>   
  </httpModules>   
  </system.web>  
  Custom.aspx页面内容:   
    
  <script   language="c#"   runat="server">   
  public   void   page_load(Object   obj,EventArgs   e)   
  {   
    lblMessage.Text   =   "<H1>Hi,   "   +   User.Identity.Name   +   "</H1>";   
    if(User.IsInRole("Administrator"))   
          lblRole.Text="<H1>You   are   an   Administrator</H1>";   
    else   if(User.IsInRole("User"))   
          lblRole.Text   =   "<H1>You   are   a   normal   user</H1>";   
  }   
  </script>   
  <form   runat="server">   
  <asp:Label   id="lblMessage"   forecolor="red"   font-size="10pt"   runat="server"/>   
  <asp:Label   id="lblRole"   forecolor="red"   font-size="10pt"   runat="server"/>   
  </form>

或者使用后者:

using System;
using System.Web;
namespace MyModule
{
    public class MyModule : IHttpModule
    {
        public void Init(HttpApplication application)
        {
            application.AcquireRequestState += (new
            EventHandler(this.Application_AcquireRequestState));
        }
        private void Application_AcquireRequestState(Object source, EventArgs e)
        {
            HttpApplication Application = (HttpApplication)source;
            User user = Application.Context.Sesseion["User"];  //获取User
            string url = Application.Context.Request.Path;
            //获取客户访问的页面
            Module module = xx; //根据url得到所在的模块
            if (!RightChecker.HasRight(user, module))
                Application.Context.Server.Transfer("ErrorPage.aspx");
            //如果没有权限,引导到错误处理的页面
        }
        public void Dispose()
        {
        }
    }
}

转载于:https://www.cnblogs.com/zc22/archive/2007/12/04/982963.html

使用httpModule做权限系统相关推荐

  1. ToB产品设计:用户权限系统解析

    ToB产品设计:用户权限系统解析 文章以产品经理的角度思考,对权限系统的核心进行剖析,抽象出权限系统中的核心要素,并结合钉钉的一些做法对权限系统进行介绍. 一.什么是用户权限系统 权限管理系统是任何一 ...

  2. 万能通用!权限系统就该这么设计!

    大家好,我是老赵.今天给大家介绍一下权限系统的设计以及主流的五种权限模型. 权限管控可以通俗的理解为权力限制,即不同的人由于拥有不同权力,他所看到的.能使用的可能不一样.对应到一个应用系统,其实就是一 ...

  3. 权限系统就该这么设计(万能通用),稳的一批!

    权限管控可以通俗的理解为权力限制,即不同的人由于拥有不同权力,他所看到的.能使用的可能不一样.对应到一个应用系统,其实就是一个用户可能拥有不同的数据权限(看到的)和操作权限(使用的). 主流的权限模型 ...

  4. 权限系统就该这么设计,yyds

    这篇文章就来介绍一下权限系统的设计以及主流的五种权限模型. 权限管控可以通俗的理解为权力限制,即不同的人由于拥有不同权力,他所看到的.能使用的可能不一样.对应到一个应用系统,其实就是一个用户可能拥有不 ...

  5. spring和mybatis结合做简单的增删查改系统_搭建后台系统权限系统的经验总结

    关于讨论后台系统中的权限系统的文章与理论有很多,而笔者就结合自己的认知与项目经验,与大家分享搭建权限系统的要点. 作为后台产品经理,相信大家都有接触过权限系统,权限系统是后台系统中不可缺少的部分,可以 ...

  6. 职场不可怜弱者,求真务实、做深做透,坚持真理、鉴定信念,走火入魔.NET通用权限系统简易物理结构图解

    坚持真理.脚踏实地.做国人值得骄傲的软件产品,求真务实.做深做透,职场不可怜弱.无知者的打击就是对牛放屁,有一颗钢铁般坚强的心.10年如一日的对管理软件的深入研究激情,不做眼高手低的中国特色程序员,一 ...

  7. (附表设计)不是我吹!超级全面的权限系统设计方案面世了

    点击上方"方志朋",选择"设为星标" 回复"666"获取新整理的面试资料 来源:cnblogs.com/iceblow/p/11121362 ...

  8. EasyUI权限系统

    UI完全参照死马的权限系统.特此,我对死马强烈的表示,我爱死你了..来亲个.哈哈.受益匪浅啊. 最近看了很多套权限系统,比如浪奔的权限系统,也是基于EasyUI的,是mvc4的.特点是,有弹出框选择赋 ...

  9. 如何设计网站权限系统(转载)

    作者:Vance 链接:https://www.zhihu.com/question/20313385/answer/118095995 来源:知乎 著作权归作者所有.商业转载请联系作者获得授权,非商 ...

最新文章

  1. python因数之和等于数字本身_python找出因数与质因数的方法
  2. 程序员求职之道(《程序员面试笔试宝典》)之面试官箴言?
  3. Qt 中容器类型的控件
  4. mysql运维管理-mysqldump 备份与恢复数据库20
  5. CSS练习_云层效果
  6. Azure PowerShell (9) 使用PowerShell导出订阅下所有的Azure VM的Public IP和Private IP
  7. linux lddbus设备,Linux设备驱动程序学习(14)-Linux设备模型(各环节的整合)
  8. 集成CAS单点登录 决策系统的配置以及注意事项
  9. 雷神开机logo更改_笔记本电脑开机LOGO太丑?大神教你来更换
  10. 平面设计中的网格系统pdf_一本好书 | 排版圣经:设计中的网格系统
  11. Windows操作技巧0001--Windows 10 修改用户名文件夹名称
  12. Flink的基础概念
  13. 主流大数据存储解决方案评析
  14. Mac环境配置SSH Key
  15. Bugku Misc 清凉一夏 wp
  16. 全球人口密度大致分布
  17. 统计视角下的Bias Variance Tradeoff 和它在KNN模型中的体现
  18. C++小游戏——猜数字
  19. python consul配置中心_微服务注册发现配置中心-consul
  20. 调试工具(三):trace32

热门文章

  1. ubuntu 修改系统默认语言为英文!
  2. “华为杯”山东理工大学第十一届ACM程序设计竞赛(正式赛)
  3. Tecplot操作记录
  4. 刺猬乐队在唯品会工作过_Microsoft乐队是您从未听说过的出色智能手表和健身追踪器...
  5. AUTOSAR MCAL详解: SPI (2)
  6. 路由器dns服务器怎么才能自动改变,路由器服务器dns怎么设置技巧教程 路由器如何设置修改dns最好...
  7. GIthub上关于新冠肺炎数据整理的项目汇总
  8. foxmail皮肤_确实很棒!Foxmail 7.1邮箱客户端体验
  9. CodeForces 757 E.Bash Plays with Functions(积性函数+dp)
  10. [linux-023]在thinkpad T480上安装ubuntu 20.04 LTS