I want to make an authentication in the App.xaml.cs class that if user exists in the database I want to direct user to member page otherwise want to direct user public page. I know how to use rootframe navigating but the problem is even though my webervice async method is written before RootFrameNavigating its not executed before it. my code is here
in App constructor
dclient.GetUserByPhoneIdCompleted += new EventHandler<GetUserByPhoneIdCompletedEventArgs> (dclient_GetUserByPhoneIdCompleted);
dclient.GetUserByPhoneIdAsync(GetDeviceUniqueID());
if (getUserbyPhoneIdCompleted)
RootFrame.Navigating += new NavigatingCancelEventHandler(RootFrame_Navigating);
and in my method
if (e.Uri.ToString().Contains("/MainPage.xaml") != true)
return;
e.Cancel = true;
RootFrame.Dispatcher.BeginInvoke(delegate
{
if (userId == -1)
RootFrame.Navigate(new Uri(string.Format("/View/PublicPage.xaml"), UriKind.Relative));
else
RootFrame.Navigate(new Uri(string.Format("/View/WelcomePage.xaml"), UriKind.Relative));
});
and in my method in webservice returns integer and I get the user Id there
like this
void dclient_GetUserByPhoneIdCompleted(object sender, GetUserByPhoneIdCompletedEventArgs e)
{
userId = e.Result;
getUserbyPhoneIdCompleted = true;
}