zoukankan      html  css  js  c++  java
  • 昨晚上写的关于IBuySpy里面用户权限验证方面的东西

    ASP.NET在页面的Context.User里面放了一个实现IPrincipal的对象,用来实现对已验证用户的管理。ASP.NET系统中,通常采用的方式就是扩展这个Context.User,让它里面保存定制的信息。   1、扩展方式 扩展方式基本上有两种:直接利用GenericPrincipal和自己写一个实现IPrincipal的类。IBuySpy用的前者,优点就是N简单。   Context.User = new GenericPrincipal(Context.User.Identity, roles);   roles是一个保存了当前用户的角色信息的String,各个角色间用“;”分隔,由前面的代码调用数据层中的UserDB.GetRoles()方法来得到。   自己写一个实现IPrincipal的类其实也是N简单,你只需要实现两个接口:Identity属性返回一个IIdentity的用户标识对象,IsInRole(String role)判断用户是否具有参数中的角色。下面是我写的一个替代IBuySpy中原有扩展模式的类:     public class IBSPrincipal : IPrincipal {   private IIdentity _identity; private String[] _asRole;   下面是两个构造函数:   public IBSPrincipal(IIdentity identity, String roles) { _identity = identity; _asRole = roles.Split(‘;’); }   public IBSPrincipal(IIdentity identity, String[] roles) { _identity = [...]
  • 相关阅读:
    内存问题定位与解决
    CPU问题定位与解决
    数据库优化案例——————某市中心医院HIS系统
    系统隐形杀手——阻塞与等待
    SQL Server常见问题介绍及快速解决建议
    CVTE实习感想--2014.10秋招
    Spring AOP的理解
    一些Java面试问题
    举几个大数据的例子
    Java中乐观锁与悲观锁的实现
  • 原文地址:https://www.cnblogs.com/kaneboy/p/2333679.html
Copyright © 2011-2022 走看看