Search code examples
c#xamlwindows-8.1-universal

XAML Force logout (force page navigation)


I have a helper class containing a method LogOut(). This is supposed to be logging of the user and redirect it to the LoginPage.

For some reason, it ignores the page navigation. It should be able to be called anywhere in the application at any point in code execution.

public static class AuthHelper
{
    public static void Logout()
    {
        //cleaning some stored credentials here...

        //force back to app start
        Frame frame = (Frame)Window.Current.Content;
        frame.Navigate(typeof(LoginPage));
    }

Solution

  • If you want to redirect the user to the login page anywhere in your app you can do it like this: Window.Current.Content = new LogInView() this will also clear the navigation history of your root frame, making it impossible to go back.