Ejemplo n.º 1
0
        /// <summary>
        /// Saves the current sign-in information (username+token) as a browser cookie
        /// and to local storage so automatic sign-in can occur with the next session. If the user is not
        /// signed in, removes the token from local storage - keeps the username to
        /// seed the sign-in dialog.
        /// </summary>
        void SaveTokenToStorage()
        {
            if (Current != null) // success
            {
                // save the cookie
                //
                CachedSignIn signIn = new CachedSignIn()
                {
                    Email = Current.Username, FullName = Current.FullName, Token = this.Token
                };
                string json = WebUtil.SaveObject <CachedSignIn>(signIn);
                WebUtil.SetCookie("esri_auth", HttpUtility.UrlEncode(json), ArcGISOnlineEnvironment.HostDomain, "/", 14);
            }
            else
            {
                WebUtil.DeleteCookie("esri_auth", ArcGISOnlineEnvironment.HostDomain);
            }

            // save to username to isolated storage to seed the sign-in dialog later
            //
            if (!IsolatedStorageFile.IsEnabled || Current == null)
            {
                return;
            }

            IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;

            if (settings.Contains("username"))
            {
                settings["username"] = Current.Username;
            }
            else
            {
                settings.Add("username", Current.Username);
            }

            settings.Save();
        }