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 = [...]
  • 相关阅读:
    GRYZ20211029模拟赛解题报告
    LG 题解 CF1545B AquaMoon and Chess
    GRYZ10.27模拟赛解题报告
    开博客通告
    民科吧编程赛 题解
    民科吧编程赛 试题
    四则运算开平方——对民科吧编程大赛题目的再探究
    The First
    机械手相机9点坐标标定-基于C#+EmguCV
    Emgucv图像处理工具
  • 原文地址:https://www.cnblogs.com/kaneboy/p/2333679.html
Copyright © 2011-2022 走看看