首页 > 解决方案 > 此站点无法从 dotnet linux 提供安全连接 asp.net core

问题描述

我目前正在使用 asp.net core 2.1 开发一个 API。当我在 Windows 中使用 ide Visual Studio 2019 时,我在运行项目时没有问题,但现在我使用的是 manjaro linux 并且我使用 dotnet 控制台进行编译时出现错误: 此站点无法提供安全连接 err_ssl_protocol_error

在此处输入图像描述

我见过的大多数解决方案都是使用框架 asp.net 或更改 Visual Studio IDE 的选项,所以我无法在我的项目中实现它。我试过添加:

.UseSetting("https_port", "5000")

在 program.cs 中,但它不起作用

类程序.cs

public static void Main(string[] args)
{
    var host = CreateWebHostBuilder(args).Build();
    RunSeeding(host);//esta llamando el alimentador de la base de datos
    host.Run();
}

private static void RunSeeding(IWebHost host)
{
    var scopeFactory = host.Services.GetService<IServiceScopeFactory>();
    using (var scope = scopeFactory.CreateScope())
    {
        var seeder = scope.ServiceProvider.GetService<SeedDb>();
        seeder.SeedAsync().Wait();
    }
}

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
    WebHost.CreateDefaultBuilder(args)
        .UseSetting("https_port", "5000")
        .UseStartup<Startup>();

configure.cs 类

 public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    if (env.IsDevelopment())
    {
        app.UseDeveloperExceptionPage();
    }
    else
    {
        // 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.UseMvc();                


    app.UseCors("AllowSpecificOrigin");


}

标签: c#linuxasp.net-core

解决方案


我能够通过以下方式在我的 asp.net 核心项目上解决此问题:

  1. 通过右键单击解决方案资源管理器中的项目并选择属性来打开项目属性
  2. 打开调试选项卡
  3. 在“Web 服务器设置”下,选中“启用 SSL”

现在,当我调试应用程序时,它会自动启动到 https URL。


推荐阅读