[英]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.