2

I intend to use currentprincipal and I searched that the property is static , so it must be shared, Actually I need it to be different not shared. as I write some code I see the currentprincipal is different after 2 users logged in to application, is it right , can I be sure of being different of the property? Actually my users logged in to application and call my function through WCF! please ask me to clear if my explanation is not enough, thanks in asvance

  • As @Backs notes: the short answer is "no"; in WCF the principal is per-request, and there's even an injection point you can use to add your own principal implementation on a per-request basis. – Marc Gravell Dec 18 '17 at 09:29

1 Answers1

5

System.Threading.Thread.CurrentPrincipal returns IPrincipal for current thread. Do your users use the same thread at one moment? I think, no.

Backs
  • 24,430
  • 5
  • 58
  • 85
  • thanks. right, it seems wcf open a new thread for every request, but I reed that the current principal is inherited from main thread of application, is that right? when we coding we see 3 different property , current thread, current principal and current context . So I thought current principal is not related to current thread. !! –  Dec 18 '17 at 09:44
  • MSDN: "Gets or sets the thread's current principal" . I understand it returns current principal OF the thread, if we assume the thread as MAIN thread of app, so it must be shared! but I iterate as I code I saw different principals and it seems your answer is right!! –  Dec 18 '17 at 09:47
  • @Hessam about what MAIN thread do you talk? In desktop application? Do your users use one PC with one application at the moment? No. WCF thread uses one thread per request, so before processing WCF set principal and other settings based on configuration – Backs Dec 18 '17 at 09:54
  • the users connect to wcf from a webapi, my wcf hosted in a console application. so consider the console app thread as MAIN thread. when a user call a method of wcf, is the system.thread.curretnprincipal different from MAIN.principal? if it is yes, so the problem solved!!! but if the principals are the same it causes a problem for me!! –  Dec 18 '17 at 10:08
  • @Hessam if you turn on any type of authentication it will differ: https://msdn.microsoft.com/en-us/library/ff406125.aspx – Backs Dec 18 '17 at 10:21