【问题标题】:Unable to start Kestrel - System.InvalidOperationException on Linux无法启动 Kestrel - Linux 上的 System.InvalidOperationException
【发布时间】:2021-02-04 21:29:23
【问题描述】:

我最近更换了操作系统,从 Ubuntu 20.04 到 KDE Neon 5.21。我用 Rider IDE 安装了 .NET CORE 3.1.9。
所以当我尝试执行一个 asp.net 核心应用程序时,它会引发以下异常:

/home/toastedguy2/dotnet/dotnet /home/toastedguy2/Downloads/Food-Town/WebUI/bin/Debug/netcoreapp3.1/WebUI.dll
批评: Microsoft.AspNetCore.Server.Kestrel[0]
无法启动 Kestrel。
System.InvalidOperationException:无法配置 HTTPS 端点。未指定服务器证书,默认开发人员证书找不到或已过期。要生成开发人员证书,请运行“dotnet dev-certs https”。要信任证书(仅限 Windows 和 macOS),请运行“dotnet dev-certs https --trust”。 有关配置 HTTPS 的更多信息,请参阅https://go.microsoft.com/fwlink/?linkid=848054

在 Windows 或 Ubuntu 上我从来没有想过,所以我不确定发生了什么。
这是我的 program.cs 类的代码:

public class Program
{
    public static void Main(string[] args)
    {
        CreateHostBuilder(args).Build().Run();
    }

    public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
            .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); });
}

现在这是我的 Startup.cs 文件的代码:

public class Startup
{
    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }

    public IConfiguration Configuration { get; }

    // This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddControllersWithViews();
        services.AddDbContextPool<FoodTownDbContext>(options =>
            options.UseSqlServer(Configuration.GetConnectionString("Standard")));
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        else
        {
            app.UseExceptionHandler("/Home/Error");
            // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
            app.UseHsts();
        }

        app.UseHttpsRedirection();
        app.UseStaticFiles();

        app.UseRouting();

        app.UseAuthorization();

        app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllerRoute(
                name: "default",
                pattern: "{controller=Home}/{action=Index}/{id?}");
        });
    }
}

PD:它发生在每个单独的 asp.net 核心应用程序上。

【问题讨论】:

    标签: linux asp.net-mvc asp.net-core asp.net-core-mvc kde-plasma


    【解决方案1】:

    看起来我安装的是 dotnet 核心运行时而不是 SDK,所以这就是它不起作用的原因。

    【讨论】:

      猜你喜欢
      • 2020-04-20
      • 2021-12-12
      • 2022-01-07
      • 1970-01-01
      • 2023-03-23
      • 2019-02-08
      • 2014-03-09
      • 1970-01-01
      • 2022-12-05
      相关资源
      最近更新 更多