繁体   English   中英

更改 Authorize 属性的默认重新路由

[英]Change default reroute of Authorize attribute

我没有使用默认的 NET Core 身份,我已经创建了自己的 AccountController,问题是当我在 controller 上使用“授权”属性时,未经授权的用户被重定向到“身份/页面/帐户”。

我试图从 Setup.css 更改路线

        services
            .ConfigureApplicationCookie(options =>
            {
                options.LoginPath = "/Account/Login";
                options.LogoutPath = "/Account/Logout";
                options.AccessDeniedPath = "/AccessDenied";
            });

但目前没有成功

            services
                .AddAuthentication()
                .AddGoogle(options =>
                {
                    IConfigurationSection googleAuthNSection =
                        this.configuration.GetSection("Authentication:Google");

                    options.ClientId = this.configuration["Authentication:Google:ClientId"];
                    options.ClientSecret = this.configuration["Authentication:Google:ClientSecret"];
                });

如果您想通过ConfigureApplicationCookie设置,您需要使用AddIdentity而不是AddDefaultIdentity

或者您可以尝试配置CookieAuthenticationOptions来满足您的要求。

services.PostConfigure<CookieAuthenticationOptions>(IdentityConstants.ApplicationScheme,
options =>
{

    options.LoginPath = "/Account/Login";
    options.LogoutPath = "/Account/Logout";
    options.AccessDeniedPath = "/AccessDenied";
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM