¿Cómo guardar el estado de inicio de sesión en Windows Phone 8?

I'm trying to build an app for WP8 with a login page. I want to save the user login state so that the end-user will not have to retype his/her credentials, my app is a HTML page embedded in the webbrowser control. Someone Can help me how save login state ?

preguntado el 04 de septiembre de 13 a las 02:09

1 Respuestas

First of all if the website you are trying to log in to is not yours then what you ask for cannot be done.

Now assuming that you are using a WebBrowser in your XAML code and that the website you log in to is yours lets say you have a login successfull method:

there you have to call this code:

window.external.notify("LogInSuccess");

Entonces tu WebBrowser debería ser así:

<phone:WebBrowser HorizontalAlignment="Stretch" Name="webBrowserControl" VerticalAlignment="Stretch" IsScriptEnabled="True" ScriptNotify="JavaScriptNotify"/>

And the method that gets called in .cs file should actually store a success value into isolated storage that will be checked every time you open the login page:

void JavaScriptNotify(Object sender, NotifyEventArgs notifyArgs)
{
    // Check if the value is correct:
    if (notifyArgs.Value.Equals("LogInSuccess"))
    {
        // Save State to Isolated Storage
        var settings = IsolatedStorageSettings.ApplicationSettings;
        settings.Add("loginStatus ", "success");
    }
}

Finally you should override the constructor method of your login page to the following:

public LoginPage() { var loginStatus = settings["loginStatus "].ToString(); if (loginStatus.Equals(success)) { NavigationService.Navigate(new Uri("/PageAfterLoginPage.xaml, UriKind.Relative)); } }

And for this to be complete override the OnNavigatedTo method of PageAfterLoginPage.xaml and add the following code:

NavigationService.RemoveBackEntry();

Last part will just remove the login page from the stack so that when the user clicks the back button wont be navigated to that screen again.

Respondido el 04 de Septiembre de 13 a las 22:09

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.