【发布时间】:2021-11-01 07:48:09
【问题描述】:
我在 .Net core 3.1 上,使用 OpenIDConnect 进行身份验证,这是我的 startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;
})
.AddCookie()
.AddOpenIdConnect("test",o =>
{
o.SignInScheme = "Cookies";
o.SignOutScheme = "Cookies";
o.ClientId = "test";
o.ClientSecret = "gs";
o.Authority = "https://test";
o.ResponseType = OpenIdConnectResponseType.CodeIdToken;
o.MetadataAddress = "https://test/.well-known/openid-configuration";
o.SaveTokens = true;
o.GetClaimsFromUserInfoEndpoint = true;
o.Scope.Add("openid");
o.Scope.Add("profile");
});
services.AddControllersWithViews();
services.AddRazorPages();
}
这是我的 Home 控制器和动作 Login with [Authorize] 属性
[Authorize]
public IActionResult Login()
{
return View();
}
登录按钮位于主文件夹 Index.cshtml
<a asp-controller="Home" asp-action="Login" target="_self" role="menuitem" class="btn btn-primary" type="button" id="btnLogin" aria-label="Log in to your account">LogIn</a>
当我点击登录按钮时,这是错误:
没有找到该网址的网页:https://localhost:34343/Account/Login?ReturnUrl=%2FHome%2FLogin
为什么要进入帐户/登录?
【问题讨论】:
标签: c# .net-core model-view-controller openid-connect