简体   繁体   English

如何在Windows Phone 8中保存登录状态?

[英]How to save log-in state in Windows Phone 8?

I'm trying to build an app for WP8 with a login page. 我正在尝试使用登录页面为WP8构建应用程序。 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. 我想保存用户登录状态,以便最终用户不必重新输入他/她的凭据,我的应用程序是嵌入在webbrowser控件中的HTML页面。 Someone Can help me how save login state ? 有人可以帮助我如何保存登录状态?

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: 现在,假设您在XAML代码中使用WebBrowser ,并且您登录的网站是您的网站,那么可以假设您有一个成功登录方法:

there you have to call this code: 在那里,您必须调用以下代码:

window.external.notify("LogInSuccess");

Then your WebBrowser should be like this: 然后您的WebBrowser应该是这样的:

<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: .cs文件中调用的方法实际上应该将成功值存储到隔离的存储中,每次打开登录页面时都会检查该成功值:

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(); 公共LoginPage(){var loginStatus = settings [“ loginStatus”] .ToString(); if (loginStatus.Equals(success)) { NavigationService.Navigate(new Uri("/PageAfterLoginPage.xaml, UriKind.Relative)); } } 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: 为此,请重写OnNavigatedTo方法并添加以下代码:

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. 最后一部分将只是从堆栈中删除登录页面,以便当用户单击“后退”按钮时,不会再次导航到该屏幕。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何获取SQL登录用户的Windows登录用户名 - How to get Windows Log-in User Name for a SQL Log in User 如何为我的常规 Microsoft 帐户注册安全密钥(用于 windows 登录)? - How do i register a security key (for windows log-in) for my regular Microsoft accounts? 如何仅使用一个命令在本机Windows telnet客户端程序中登录和执行ftp命令 - how to log-in and execute ftp commands in native windows telnet client program using only one command 用户登录Windows时,ToolStripButton从PropertyGrid中消失 - ToolStripButton disappear from PropertyGrid when user log-in to Windows 枚举VB6中Windows的“登录屏幕”用户帐户 - Enumerating Windows “log-in screen” user accounts in VB6 将Windows Phone 8状态更改为静音 - Change windows phone 8 state to Silent Windows Phone应用程序状态和摄像头 - Windows Phone App State & Camera 如何使用Delphi和JEDI Docking保存当前Windows状态? - How to save current windows state using Delphi and JEDI Docking? 单击UWP中的“保存”按钮后,如何自动保存从Windows Phone捕获的图像? - How to save Image that is captured from windows phone automatically after click save button in UWP? 为Windows Phone 8.1创建崩溃日志 - Creating Crash Log for Windows Phone 8.1
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM