views:

183

answers:

1

I don't know exactly how to explain it, but here is basically how my problem could be reproduced:

  • Create a WPF Windows Application Project in VB.NET (don't create, just keep reading this, unless you don't believe me...)
  • Click the Window's header to create a Window.Loaded event-handler and to navigate to it.
  • Add the following to the event-handler:
    My.User.CurrentPrincipal = New GenericPrincipal( _
    New GenericIdentity("username"), Nothing)
    Dim authenticated = My.User.CurrentPrincipal.IsAuthenticated
    MessageBox.Show(authenticated) 'True'
  • Go back to the window designer and add a Button to the Window1.
  • Click the Button to create its Click event-handler and navigate to it.
  • Add the following content to it:
    Dim authenticated = My.User.CurrentPrincipal.IsAuthenticated
    MessageBox.Show(authenticated) 'False'
  • Run the application, see the results
  • WHY ON THE EARTH IS IT FALSE NOW!?!?

UPDATE: I reported a bug at: http://connect.microsoft.com/WPF/feedback/ViewFeedback.aspx?FeedbackID=513731, please vote or post a workaround, and update me when you do so, thanks in advance.

Any workarounds will be welcommed!

+1  A: 

I was hoping to find a definitive explanation for this behavior, but no such luck (yet). I do think I can offer you a work-around, though, which is to assign the custom principal object via AppDomain.SetThreadPrincipal (typically AppDomain.CurrentDomain.SetThreadPrincipal).

EDIT:

It turns out someone brought up this issue on the MSDN Forums. The discussion thread documents the work-around I already referenced, along with an explanation of the behavior.

Daniel Pratt
Thank you so much, that's a good workaround!Please go to that link in my querstion, vote and click "I can reproduce".
Shimmy