C# 这个网站可以’;t提供安全连接。localhost发送了无效响应

C# 这个网站可以’;t提供安全连接。localhost发送了无效响应,c#,ssl,https,.net-core,C#,Ssl,Https,.net Core,我正在使用Visual Studio代码中的命令DotNet run运行我的DotNet Core 3.0应用程序。应用程序运行成功,并显示urlhttps://localhost:5001/和https://localhost:5000/在控制台中。当我打开https://localhost:5001/在浏览器中显示: 找不到该网址的网页: HTTP错误404 当我运行https://localhost:5000/,上面写着: 此网站无法提供安全连接。localhost发送了无效响应 我确实运

我正在使用Visual Studio代码中的命令
DotNet run
运行我的DotNet Core 3.0应用程序。应用程序运行成功,并显示url
https://localhost:5001/
https://localhost:5000/
在控制台中。当我打开
https://localhost:5001/
在浏览器中显示:

找不到该网址的网页: HTTP错误404

当我运行
https://localhost:5000/
,上面写着:

此网站无法提供安全连接。localhost发送了无效响应

我确实运行了命令
dotnet dev certs https--trust
。问题在哪里

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>();
            });
}
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.AddControllers();
        services.AddScoped(typeof(IRepository<>), typeof(Repository<>));

        services.AddDbContext<ExperionContext>(options =>
    options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
    }

    // 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();
        }

        app.UseHsts();

        app.UseHttpsRedirection();

        app.UseRouting();

        app.UseAuthorization();

        app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllers();
        });
    }
}
公共类程序
{
公共静态void Main(字符串[]args)
{
CreateHostBuilder(args.Build().Run();
}
公共静态IHostBuilder CreateHostBuilder(字符串[]args)=>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder=>
{
webBuilder.UseStartup();
});
}
Startup.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>();
            });
}
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.AddControllers();
        services.AddScoped(typeof(IRepository<>), typeof(Repository<>));

        services.AddDbContext<ExperionContext>(options =>
    options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
    }

    // 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();
        }

        app.UseHsts();

        app.UseHttpsRedirection();

        app.UseRouting();

        app.UseAuthorization();

        app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllers();
        });
    }
}
公共类启动
{
公共启动(IConfiguration配置)
{
配置=配置;
}
公共IConfiguration配置{get;}
//此方法由运行时调用。请使用此方法将服务添加到容器中。
public void配置服务(IServiceCollection服务)
{
services.AddControllers();
addScope(typeof(IRepository)、typeof(Repository));
services.AddDbContext(选项=>
options.UseSqlServer(Configuration.GetConnectionString(“DefaultConnection”));
}
//此方法由运行时调用。请使用此方法配置HTTP请求管道。
public void配置(IApplicationBuilder应用程序、IWebHostEnvironment环境)
{
if(env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseHsts();
app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(端点=>
{
endpoints.MapControllers();
});
}
}

注意:我添加了行
app.UseHsts()稍后用于实验。没有它也无法工作。

您的服务器只侦听端口5001(而不是5000)。标题的格式错误。调试的最佳方法是使用诸如wireshark或fiddler之类的嗅探器并检查第一个请求中的头。如果您有一个可以工作的应用程序,则将工作头与非工作头进行比较。您正在使用SSL建立安全连接https(而非http)。首先,在建立http连接之前建立TCP SSL连接。SSL最新版本为3.0,如果您的internet设置不允许SSL,则可能会失败。如果不查看嗅探器,则很难进行调试。