程序说明:先把所有权限读出来缓存到内存中,然后与每个用户的权限比较,如果权限表中存在,则有权限。另外还有一个问题:我每次重新设置权限之后,必须重启应用程序池,才能更新新的权限设置。static 变量只存在应用程序池中?

解决方案 »

  1.   

    014-10-23 09:08:54-rolePermissionList.RemoveFilter():System.ArgumentOutOfRangeException: 索引必须位于该列表的界限内。
    参数名: index
       在 System.Collections.Generic.List`1.Insert(Int32 index, T item)
       在 Hyun.Entities.ListBase`1.ApplyFilter()
       在 Hyun.WebService.MainWebService.HasPermission(Result r)
    -----------------------
    2014-10-23 09:08:54-rolePermissionList.ApplyFilter:System.NullReferenceException: 未将对象引用设置到对象的实例。
       在 Hyun.WebService.MainWebService.<>c__DisplayClass2.<HasPermission>b__0(VRolePermissionList rp)
       在 Hyun.Entities.ListBase`1.ApplyFilter(Predicate`1 match)
       在 Hyun.WebService.MainWebService.HasPermission(Result r)
      

  2.   

    你这程序,不是仅仅在没有读取过或者内容为空时才读取一次数据、以后不再读取嘛!不用去找“对象保存在哪里”的问题。另外,asp.net程序随时会重启,会经常造成Session、Application、static变量引用的对象的“丢失”现象。如果想缓存数据,就真正学会使用Cache,了解Cache数据随时可能丢失的事实。如果你不是想真正缓存对象,以为static引用的对象不丢失,那么就写c/s程序,而不是asp.net程序。
      

  3.   

    看你用了static,static整个进程只有一份,是不是并发造成的。试一试写入static 容器的时候用lock锁定一下,确保只有一个线程在同一个时间可以写入。重启application pool就是重启asp.net的进程。
      

  4.   

    List<>在msdn中对于thread safety的描述It is safe to perform multiple read operations on a List<T>, but issues can occur if the collection is modified while it’s being read. To ensure thread safety, lock the collection during a read or write operation. To enable a collection to be accessed by multiple threads for reading and writing, you must implement your own synchronization. For collections with built-in synchronization, see the classes in the System.Collections.Concurrent namespace. For an inherently thread–safe alternative, see the ImmutableList class.来自:
    http://msdn.microsoft.com/en-us/library/6sh2ey19(v=vs.110).aspx
      

  5.   

    Session保存信息容易丢失,建议使用Application Cache
      

  6.   

    web.config里面SessionState的Mode设置的是Inproc吧,改成StateServer试试,当然之前得把Asp.Net状态服务启动起来。