예제 #1
0
        public async Task <IActionResult> Logout(LogoutInputModel model)
        {
            // build a model so the logged out page knows what to display
            var vm = await BuildLoggedOutViewModelAsync(model.LogoutId);

            if (User?.Identity.IsAuthenticated == true)
            {
                // delete local authentication cookie
                await HttpContext.SignOutAsync();

                // raise the logout event
                await _events.RaiseAsync(new UserLogoutSuccessEvent(User.GetSubjectId(), User.GetDisplayName()));
            }

            // 检查是否需要在上游身份提供程序上触发签名
            // check if we need to trigger sign-out at an upstream identity provider
            if (vm.TriggerExternalSignout)
            {
                // build a return URL so the upstream provider will redirect back
                // to us after the user has logged out. this allows us to then
                // complete our single sign-out processing.
                string url = Url.Action("Logout", new { logoutId = vm.LogoutId });

                // this triggers a redirect to the external provider for sign-out
                return(SignOut(new AuthenticationProperties {
                    RedirectUri = url
                }, vm.ExternalAuthenticationScheme));
            }
            // var returnUrl = result.Properties.Items["returnUrl"];
            // if (_interaction.IsValidReturnUrl(returnUrl) || Url.IsLocalUrl(returnUrl))
            // {
            //     return Redirect(returnUrl);
            // }

            var refererUrl = Request.Headers["Referer"].ToString();

            return(Redirect(refererUrl));
            // return Redirect("~/");
            //return View("LoggedOut", vm);
        }
        public async Task <IActionResult> Logout(LogoutInputModel model)
        {
            var vm = await _account.BuildLoggedOutViewModelAsync(model.LogoutId);

            if (vm.TriggerExternalSignout)
            {
                string url = Url.Action("Logout", new { logoutId = vm.LogoutId });
                try
                {
                    // hack: try/catch to handle social providers that throw
                    await HttpContext.Authentication.SignOutAsync(vm.ExternalAuthenticationScheme,
                                                                  new AuthenticationProperties { RedirectUri = url });
                }
                catch (NotSupportedException) // this is for the external providers that don't have signout
                {
                }
                catch (InvalidOperationException) {} // this is for Windows/Negotiate
            }

            // delete local authentication cookie
            await HttpContext.Authentication.SignOutAsync();

            return(View("LoggedOut", vm));
        }