Async Login Issue

Async Login Issue

Old forum URL:

CrikeyMoses posted on Monday, May 09, 2011

I'm new to Silverlight and CSLA, please correct me where I'm wrong:
I have a Silverlight application with a login form on a childwindow that basically calls this: Business.Server.Security.AppPrincipal.Login(userName, password);
AppPrinciple has this login method
 public static void Login(string username, string password)


            AppIdentity.GetAppIdentity(username, password, (o, e) =>


                if (e.Error == null && e.Object != null)






The problem I'm having is that when i check to see if the user is logged in on the ViewModel "if (Csla.ApplicationContext.User.Identity.IsAuthenticated)" the SetPrincipal method has not yet been called.  Only once you try login again does it know you are authenticated.

RockfordLhotka replied on Monday, May 09, 2011

The async nature of Silverlight makes this a little tricky. You need to rethink how your login process will work, and make the overall process async.

I usually have a viewmodel for my main shell window, and it has a property like ApplicationReady or AuthenticatedUser or something. If that value is false, the majority of the UI is blocked out by the shell (often with a Canvas overlay).

The login window can do the login process, but once it is complete (one way or the other), it should change the view to the welcome page or something.

I assume you are using some MVVM framework if you are using a viewmodel. So your MVVM framework will provide a way for a viewmodel (like the LoginViewModel) to ask the shell to display a new view.

Similarly, your MVVM framework probably has a messaging component, so your login viewmodel code can send a "logged in" or "logged out" message, and the main shell's viewmodel can listen for that message so it knows to update the ApplicationReady property - and that'll unlock the app through data binding.

As you might imagine, there are many variations on this theme - so I'm just describing the high level concepts.

Copyright (c) Marimer LLC