This my code:
public static void BeginLogin(string account, string password, EventHandler callback)
{
var perform = new EventHandler<DataPortalResult<SecurityIdentity>>(delegate(object o, DataPortalResult<SecurityIdentity> e)
{
if (e.Error == null && e.Object != null)
SetPrincipal(e.Object);
else
Logout();
callback(o, null);
});
SecurityIdentity.GetIdentity(account, password, perform);
}
private static bool SetPrincipal(IIdentity identity)
{
if (identity.IsAuthenticated)
{
var principal = new SecurityPrincipal(identity);
ApplicationContext.User = principal;
}
OnNewUser();
return identity.IsAuthenticated;
}
If I use asynchronous calls the ApplicationContext.User in the Callback can set up correctly, when you switch to another window ApplicationContext.User reverted to the State is not set.
I've found in the Forum, there are a number of ways, are not handled correctly.And after using the BeginLogin network exceptions will not be caught.
Do you have any good suggestions?