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