0

I am developping a Windows Phone 8 application in C#/Xaml. When the user launched the app, he arrives on a log page and then he enters in the "real" app. My problem is: how can the user log out? I tried to just come back on the log page by clicking on a button but then i have trouble with the back button. Is there a way to kill the app manually? What are the best practices to do that? Thanks for your help!

EclipseVS
  • 13
  • 4
  • 2
    Your problem is a bit vague. You should give us some more specifics about the control flow of your app and what kind of login you're using – Saverio Terracciano Jun 04 '14 at 11:53
  • For now, I just check an id and a password which are stored as global variables. Later, it will be connected to a webservice. I am using a PasswordBox and a TextBox. When the user click on the button "connexion", I check if it is the right ID/Password and if it is correct, I display a pivot page. I added a button "disconnexion" in the pivotPage which bring you back to the log page. But this way, when the user click the back button, he comes back to pivot page without having to re-enter the id/password. – EclipseVS Jun 04 '14 at 12:08
  • Then check my answer below, but you need to write some code that checks the user's session inside the OnNavigatedTo method of your pivot page – DevBob Jun 04 '14 at 12:17
  • Here is a [link](http://stackoverflow.com/questions/13417380/close-app-on-back-button-when-on-certain-page) which has been very useful for me. – EclipseVS Jul 04 '14 at 09:14

2 Answers2

1

I would try this : A logout button wherever you want it that redirects to a xaml page stating "do you really want to logout ?" (let's call this page Logout.xaml) and in this page, you manage to redirect the user to the homepage of your app in the "Button_Click" method of your "yes" button, in the file Logout.xaml.cs.

Then, you override the OnNavigatingFrom method of the Lougout.xaml.cs file, and in this method you kill the user session.

This way, your user wants to disconnect, clicks yes, and goes back to the homepage with his session closed.

Now, if you already wanted to do that and your question is "how to kill the session ?", it depends on how you handle your user sessions

DevBob
  • 835
  • 2
  • 9
  • 29
-2

To Terminate the application you can use :

App.Current.Terminate();

There won't be any issue when using this call, but make sure you have saved all data in your app when calling this, because this call effectively kills your app immediately - ApplicationClosing even handler won't be raised after it!

Amit Bhatiya
  • 2,621
  • 1
  • 12
  • 20