![](/img/trans.png)
[英]Asp.net core 5, using Identity, how do I change the default redirect of the [Authorize] Attribute?
[英]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.