首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ASP.NET核心3.1 -健康检查UI不起作用

ASP.NET核心3.1 -健康检查UI不起作用
EN

Stack Overflow用户
提问于 2020-05-24 02:54:55
回答 1查看 9.2K关注 0票数 3

我开发了一个带有自定义健康检查的ASP.NET Core3.1MVC应用程序。它运行得很好,如下所示。

但是,UI始终是空的,因为/health总是返回空数组。

它在ASP.NET 3.1核心应用程序中,可以定位于https://github.com/prawin2k/HealhCheckMVC/tree/master/HealhCheckMVC

.NET核心版本- 3.1 (MVC)健康检查版本-最新操作系统:WindowsServer2016其他:VisualStudio2019

EN

回答 1

Stack Overflow用户

发布于 2020-07-24 15:30:14

在我的例子中,健康检查UI本身没有启动和破坏.net核心3.1WebAPI应用程序。

错误消息:某些服务无法构造(在验证服务描述符‘HealthChecks.UI.Core.Notifications.IHealthCheckFailureNotifier生命周期:作用域ImplementationType: HealthChecks.UI.Core.Notifications.WebHookFailureNotifier':无法解析服务类型'HealthChecks.UI.Core.Data.HealthChecksDb’时出错时出现错误,同时试图激活'HealthChecks.UI.Core.Notifications.WebHookFailureNotifier'.)

Fix:添加任何UI存储提供程序。在我的例子中我选择了AddInMemoryStorage()

Startup.cs

代码语言:javascript
复制
public void ConfigureServices(IServiceCollection services)
{
    ...
    
    services.AddHealthChecks() 
        .AddDbContextCheck<PollDbContext>() //nuget: Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore
        .AddApplicationInsightsPublisher(); //nuget: AspNetCore.HealthChecks.Publisher.ApplicationInsights

    services.AddHealthChecksUI() //nuget: AspNetCore.HealthChecks.UI
        .AddInMemoryStorage(); //nuget: AspNetCore.HealthChecks.UI.InMemory.Storage
        
    ...
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    ...
    
    app.UseHealthChecks("/healthcheck", new HealthCheckOptions
    {
        Predicate = _ => true,
        ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse //nuget: AspNetCore.HealthChecks.UI.Client
    });
    
    //nuget: AspNetCore.HealthChecks.UI
    app.UseHealthChecksUI(options =>
    {
        options.UIPath = "/healthchecks-ui";
        options.ApiPath = "/health-ui-api";
    });
    ...
}

appsettings.json

代码语言:javascript
复制
"HealthChecks-UI": {
    "DisableMigrations": true,
    "HealthChecks": [
        {
            "Name": "PollManager",
            "Uri": "/healthcheck"
        }
    ],
    "Webhooks": [
        {
            "Name": "",
            "Uri": "",
            "Payload": "",
            "RestoredPayload": ""
        }
    ],
    "EvaluationTimeOnSeconds": 10,
    "MinimumSecondsBetweenFailureNotifications": 60,
    "MaximumExecutionHistoriesPerEndpoint": 15
}
票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61981081

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档