{"id":2746,"date":"2015-01-07T23:23:14","date_gmt":"2015-01-07T23:23:14","guid":{"rendered":"http:\/\/putridparrot.com\/blog\/?p=2746"},"modified":"2015-01-07T23:23:14","modified_gmt":"2015-01-07T23:23:14","slug":"thread-currentprincipal-keeps-getting-reset-in-wpf","status":"publish","type":"post","link":"https:\/\/putridparrot.com\/blog\/thread-currentprincipal-keeps-getting-reset-in-wpf\/","title":{"rendered":"Thread.CurrentPrincipal keeps getting reset in WPF"},"content":{"rendered":"<p>I&#8217;m porting an app. to WPF from Windows Forms. In the Windows Forms application we used to store our own IPrincipal implementation object which stored info. about the user and a security token.<\/p>\n<p>For example<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nThread.CurrentPrincipal = \r\n    new UserPrincipal(&quot;username&quot;, token);\r\n<\/pre>\n<p>Whilst porting the code I noticed that the CurrentPrincipal kept getting reset to a GenericPrincipal object.<\/p>\n<p>Long story short, in WPF we need to call the SetThreadPrincipal on the current app domain to set the principal instead of via the CurrentPrincipal property, for example<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nAppDomain.CurrentDomain.SetThreadPrincipal(\r\n    new UserPrincipal(&quot;username&quot;, token));\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m porting an app. to WPF from Windows Forms. In the Windows Forms application we used to store our own IPrincipal implementation object which stored info. about the user and a security token. For example Thread.CurrentPrincipal = new UserPrincipal(&quot;username&quot;, token); Whilst porting the code I noticed that the CurrentPrincipal kept getting reset to a GenericPrincipal [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3,13],"tags":[],"class_list":["post-2746","post","type-post","status-publish","format-standard","hentry","category-c","category-wpf"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/2746","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/comments?post=2746"}],"version-history":[{"count":5,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/2746\/revisions"}],"predecessor-version":[{"id":2754,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/2746\/revisions\/2754"}],"wp:attachment":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/media?parent=2746"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/categories?post=2746"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/tags?post=2746"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}