WPF, custom authentication

WPF, custom authentication

Old forum URL: forums.lhotka.net/forums/t/8507.aspx


fsl posted on Wednesday, February 10, 2010

Hi

I'm using custom authentication in an WPF/VSTO application. I've implemented a custom principal and a custom identity. I'm using Csla.ApplicationContext.User to store the identity etc. I a have a main window in which I login, i.e. create the custom principal and so on. Inside one control in the UI, Csla.ApplicationContext.User.Identity returns the correct custom identity. But inside another control Csla.ApplicationContext.User.Identity returns a generic identity.. 

Any ideas why this may be happening?

Regards,

Fredrik

 

ajj3085 replied on Wednesday, February 10, 2010

It sounds like you're creating a plugin for an Office application, is that correct? 

If that's the case, its been my experience (with my Outlook plugin, at least) that the thread your code gets executed on changes, based on things outside your control (namely the Office application you're targeting). 

The only solution I've found for this is to store the principal in a static field reference when the plugin starts up and to reset it again whenever code is executed in response to the application (in my case, whenever an item is added to the Inbox or Sent Items).

fsl replied on Wednesday, February 10, 2010

Thank you, for your answer.

Yes, I'm creating an addin for outlook.

I just tried using:

 AppDomain.CurrentDomain.SetThreadPrincipal(principal);

, which so far have solved the problem.. 

ajj3085 replied on Wednesday, February 10, 2010

I thought I had tried that at one point and it would still fail sometimes.  Let me know how it goes with you, maybe I was doing something else odd too that was making that not work.

RockfordLhotka replied on Wednesday, February 10, 2010

SetThreadPrincipal() only affects threads created after that method is called. So if threads have been created before you make that call, and those threads are reused (which is likely) then you could end up on an unaffected thread that doesn't have your principal. I suspect that's why you've seen it fail sometimes.

ajj3085 replied on Thursday, February 11, 2010

Hmm... that might not be the solution then, because I was calling in respond to the Startup event Outlook triggers when your application starts up.

Copyright (c) Marimer LLC