微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用 .net core 5 完成注销过程后,如何重定向到我自己的自定义注销页面

如何解决使用 .net core 5 完成注销过程后,如何重定向到我自己的自定义注销页面

每当我从应用程序注销时,我都会进入“认”注销页面(我相信此控制器操作内置于 .net 核心)。注销后如何执行注销重定向到我的应用程序中的自定义页面?我看不到一种方法来指定这一点,这肯定是可能的吗? (它是在旧版本的 .net 中)。
我使用 azure 广告,我的应用程序托管在 azure 中。这是配置

services.Configure<CookiePolicyOptions>(options =>
        {
            // This lambda determines whether user consent for non-essential cookies is needed for a given request.
            options.CheckConsentNeeded = context => true;
            options.MinimumSameSitePolicy = SameSiteMode.Unspecified;
            // Handling SameSite cookie according to https://docs.microsoft.com/en-us/aspnet/core/security/samesite?view=aspnetcore-3.1
            options.HandleSameSiteCookieCompatibility();
        });

        

        // Sign-in users with the Microsoft identity platform
        services.AddMicrosoftIdentityWebAppAuthentication(Configuration,"AzureAd");

我在 appsettings.json 中也有这些设置

"CallbackPath": "/signin-oidc","SignedOutCallbackPath ": "/signout-callback-oidc"

我也试过这个

new RewriteOptions().Add(
            context => {
                if (context.HttpContext.Request.Path == "/AzureAD/Account/SignedOut")
                { context.HttpContext.Response.Redirect("/Home/Index"); }
            })
        );

甚至尝试使用这两种方法添加我自己的 AccountController

[HttpGet]
    public override SignOutResult SignOut()
    {
        var callbackUrl = Url.Action(nameof(SignedOut),"Account",values: null,protocol: Request.Scheme);
        return SignOut(
            new AuthenticationProperties { RedirectUri = callbackUrl },CookieAuthenticationDefaults.AuthenticationScheme,OpenIdConnectDefaults.AuthenticationScheme);
    }

    [HttpGet]
    public IActionResult SignedOut()
    {
        if (User.Identity.IsAuthenticated)
        {
            // Redirect to home page if the user is authenticated.
            return RedirectToAction(nameof(HomeController.Index),"Home");
        }

        return RedirectToAction(nameof(HomeController.Index),"Home");
    }

没有任何效果,我总是重定向到“认”注销页面。任何人都可以帮忙吗?提前致谢

解决方法

我设法解决了这个问题,我把我的 Rewite 代码改成了这个

app.UseRewriter(
        new RewriteOptions().Add(
            context => {
                if (context.HttpContext.Request.Path == "/MicrosoftIdentity/Account/SignedOut")
                { context.HttpContext.Response.Redirect("/Home/SignedOut"); }
            })
        );

这是我必须修改的部分 来自

"/AzureAD/Account/SignedOut"

"/MicrosoftIdentity/Account/SignedOut"

现在可以了

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。