我在 Startup.Auth.cs 中有以下代码:
app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{
ClientId = myclientId,
Authority = authority,
PostLogoutRedirectUri = mypostLogoutRedirectUri,
,
Notifications = new OpenIdConnectAuthenticationNotifications
{
AuthenticationFailed = (context) =>
{
context.HandleResponse();
string error = ""; //<-- what goes here?
context.OwinContext.Response.Redirect("/Home/auth_error?error_msg=" + error);
return Task.FromResult(0);
},
SecurityTokenValidated = (context) =>
{
string name = context.AuthenticationTicket.Identity.Name;
context.AuthenticationTicket.Identity.AddClaim(new Claim(ClaimTypes.Name, name, string.Empty));
return System.Threading.Tasks.Task.FromResult(0);
}
}
});
我想要做的是显示一条错误消息,说明身份验证失败的原因。我如何以字符串形式获取
AuthenticationFailed
段中的所有适当信息?
您的上下文应在
context.Exception.Message
中包含您的消息。
参见:https://learn.microsoft.com/en-us/previous-versions/aspnet/mt180967(v=vs.113)