Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/270.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 更改“授权”属性的默认重新路由_C#_Asp.net Core - Fatal编程技术网

C# 更改“授权”属性的默认重新路由

C# 更改“授权”属性的默认重新路由,c#,asp.net-core,C#,Asp.net Core,我没有使用默认的NET Core标识,并且我创建了自己的AccountController,问题是当我在控制器上使用“Authorize”属性时,未经授权的用户会被重定向到“Identity/Pages/Account” 我已尝试从Setup.css更改路线 services .ConfigureApplicationCookie(options => { options.LoginPath =

我没有使用默认的NET Core标识,并且我创建了自己的AccountController,问题是当我在控制器上使用“Authorize”属性时,未经授权的用户会被重定向到“Identity/Pages/Account”

我已尝试从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"];
                });

如果要通过
configureapplicationcokie
进行设置,则需要使用
AddIdentity
而不是
AddDefaultIdentity

或者,您可以尝试配置
CookieAuthenticationOptions
以满足您的需求

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

    options.LoginPath = "/Account/Login";
    options.LogoutPath = "/Account/Logout";
    options.AccessDeniedPath = "/AccessDenied";
});
services.PostConfigure(IdentityConstants.ApplicationScheme,
选项=>
{
options.LoginPath=“/Account/Login”;
options.LogoutPath=“/Account/Logout”;
options.AccessDeniedPath=“/AccessDenied”;
});

包括您的
AddAuthentication
调用。@KirkLarkin services.AddAuthentication().AddGoogle(选项=>{IConfigurationSection GoogleAuthentication=this.configuration.GetSection(“Authentication:Google”);options.ClientId=this.configuration[“Authentication:Google:ClientId”];options.ClientSecret=this.configuration[“Authentication:Google:ClientSecret”];});我想您有一个呼叫
AddIdentity
AddDefaultIdentity
。这是高于还是低于您对
configureapplicationcokie
的调用?@KirkLarkin它低于configureapplicationcokiesimple。检查
AccountController
中的
Logout
操作,查看其重定向到的内容。