public IAsyncResult BeginLoad(Uri targetUri, Uri currentUri, AsyncCallback userCallback, object asyncState)
        {
            AuthorizationAsyncResult result = new AuthorizationAsyncResult(userCallback, asyncState);

            result.InnerAsyncResult = this._loader.BeginLoad(targetUri, currentUri, this.HandleLoadCompleted, result);
            return(result);
        }
        public LoadResult EndLoad(IAsyncResult asyncResult)
        {
            AuthorizationAsyncResult result = AsyncResultBase.EndAsyncOperation <AuthorizationAsyncResult>(asyncResult);

            if (result.Error != null)
            {
                throw result.Error;
            }
            return(result.LoadResult);
        }
        private void HandleRequestAuthenticationCompleted(object userState)
        {
            AuthorizationAsyncResult result = (AuthorizationAsyncResult)userState;

            if (!result.CancellationRequested)
            {
                if (Authorization.Authorize(result.LoadResult.LoadedContent) == AuthorizationResult.Allowed)
                {
                    // Direct the user to the requested page
                    result.Complete();
                }
                else
                {
                    // If the user is still not authorized, he needs to be redirected
                    result.LoadResult = new LoadResult(this.DefaultSource);
                    result.Complete();
                }
            }
        }
        private void HandleLoadCompleted(IAsyncResult asyncResult)
        {
            AuthorizationAsyncResult result = (AuthorizationAsyncResult)asyncResult.AsyncState;

            if (!result.CancellationRequested)
            {
                try
                {
                    result.LoadResult = this._loader.EndLoad(result.InnerAsyncResult);
                    AuthorizationNavigationMode navigationMode = this.GetContentNavigationMode(result.LoadResult.LoadedContent);

                    if (Authorization.Authorize(result.LoadResult.LoadedContent) == AuthorizationResult.Allowed)
                    {
                        // Direct the user to the requested page
                        result.Complete();
                    }
                    else if (WebContextBase.Current.Authentication.User.Identity.IsAuthenticated ||
                             (navigationMode == AuthorizationNavigationMode.Redirect))
                    {
                        // If the user is authenticated but not authorized, he needs to be redirected
                        result.LoadResult = new LoadResult(this.DefaultSource);
                        result.Complete();
                    }
                    else if (navigationMode == AuthorizationNavigationMode.Prompt)
                    {
                        if (Authorization.Prompter == null)
                        {
                            throw new InvalidOperationException("Authorization.Prompter cannot be null when the navigationMode is 'Prompt'.");
                        }
                        // If the user is not authenticated, we need to prompt for re-authentication or redirect
                        Authorization.Prompter.RequestAuthentication(this.HandleRequestAuthenticationCompleted, result);
                    }
                }
                catch (InvalidOperationException ex)
                {
                    result.Error = ex;
                    result.Complete();
                }
            }
        }
        public void CancelLoad(IAsyncResult asyncResult)
        {
            AuthorizationAsyncResult result = AsyncResultBase.EndAsyncOperation <AuthorizationAsyncResult>(asyncResult, true);

            this._loader.CancelLoad(result.InnerAsyncResult);
        }