Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在.NET中,System.Threading.Thread.CurrentPrincipal为';t更新_.net_Multithreading_Current Principal - Fatal编程技术网

在.NET中,System.Threading.Thread.CurrentPrincipal为';t更新

在.NET中,System.Threading.Thread.CurrentPrincipal为';t更新,.net,multithreading,current-principal,.net,Multithreading,Current Principal,调试某些.NET代码时,我缺少一些基本信息: public static void CreateServiceSessionStore() { ServiceSessionStore serviceSessionStore = new ServiceSessionStore(); serviceSessionStore.SetIdentity(System.Threading.Thread.CurrentPrincipal.Identity);

调试某些.NET代码时,我缺少一些基本信息:

    public static void CreateServiceSessionStore()
    {
        ServiceSessionStore serviceSessionStore = new ServiceSessionStore();
        serviceSessionStore.SetIdentity(System.Threading.Thread.CurrentPrincipal.Identity);
        System.Threading.Thread.CurrentPrincipal = serviceSessionStore;
        // Here, CurrentPrincipal still isn't a serviceSessionStore!
    }
在这段代码中,一切似乎都进展顺利。但是…当我调试并且刚好在最后一行之前时,我正在查看System.Threading.Thread.CurrentPrincipal。该值是一个WebSessionStore对象,这是我所期望的,我认为最后一行应该将其更改为ServiceSessionStore对象。但事实并非如此。我可以查看serviceSessionStore,它包含一个serviceSessionStore对象,但在行运行之后,CurrentPrincipal仍然包含一个WebSessionStore对象。不会抛出任何错误


现在,除了这些对象的实际功能外,有人能提供一个关于它为什么拒绝更新CurrentPrincipal的想法吗

这是一个调试器工件。调试表达式在专用调试器线程上求值。CurrentPrincipal是线程执行上下文的属性。这也是它可以是静态属性的原因。不同的线程将具有不同的主体,因此调试器线程的主体不相同


您没有真正的问题。

我强烈怀疑缺乏权限(SecurityPermission)。我不知道你为什么看不到异常被抛出。有趣的理论。作为额外的奖励,这似乎是真的。恰恰!