在ASP.NET Core中,你可以使用健康检查来监视应用程序的状态。如果你在使用UI进行身份认证时遇到问题,可能是由于身份认证服务未正确配置所致。以下是一个可能的解决方案:
services.AddAuthentication(options =>
{
options.DefaultScheme = "Cookies";
options.DefaultChallengeScheme = "oidc";
})
.AddCookie("Cookies")
.AddOpenIdConnect("oidc", options =>
{
options.Authority = "https://your-identity-server.com";
options.ClientId = "your-client-id";
options.ClientSecret = "your-client-secret";
options.ResponseType = "code";
options.SaveTokens = true;
});
请确保将上述代码中的"your-identity-server.com"替换为你的身份认证服务器的URL,并将"your-client-id"和"your-client-secret"替换为你的应用程序的客户端ID和客户端密钥。
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapHealthChecks("/health");
endpoints.MapControllers();
});
请确保将上述代码中的"/health"替换为你想要使用的健康检查终点的路径。
通过上述步骤,你应该能够解决ASP.NET Core健康检查UI在身份认证上失败的问题。如果问题仍然存在,请确保你的身份认证服务和健康检查服务都正常运行,并检查日志和错误消息以获取更多详细信息。