Wrong Thread.CurrentPrincipal in async WCF end-method

后端 未结 3 1621
你的背包
你的背包 2021-02-08 15:25

I have a WCF service which has its Thread.CurrentPrincipal set in the ServiceConfiguration.ClaimsAuthorizationManager.

When I implement the ser

3条回答
  •  难免孤独
    2021-02-08 16:08

    Not really the answer to my question, but an alternate approach of implementing the WCF service (in .NET 4.5) that does not exhibit the same issues with Thread.CurrentPrincipal.

        public async Task Method1()
        {
            // Audit log call (uses Thread.CurrentPrincipal)
    
            try
            {
                return await Task.Factory.StartNew(() => this.WorkerFunction());
            }
            finally 
            {
                // Audit log result (uses Thread.CurrentPrincipal)
            }
        }
    
        private string WorkerFunction()
        {
            // perform work
            return string.Empty;
        }
    

提交回复
热议问题