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 = [...]
  • 相关阅读:
    Qt生成随机数
    Qt调用系统DLL,判断网络连接状态
    Qt操作sqlite数据库
    Qt 操作注册表
    vs报错:RC1004 unexpected end of file found
    Qt操作ini文件
    Django Admin:自动选择当前用户
    BSTR转QString
    vue-cli4,vue3打包后页面无内容
    Qt 5.12.10 国际化
  • 原文地址:https://www.cnblogs.com/kaneboy/p/2333679.html
Copyright © 2011-2022 走看看