Этот сайт не может обеспечить безопасное соединение. localhost отправил неверный ответ - PullRequest
0 голосов
/ 16 октября 2019

Я запускаю свое приложение DotNet Core 3.0 с помощью команды dotnet run из кода Visual Studio. Приложение работает успешно и отображает URL https://localhost:5001/ и https://localhost:5000/ в консоли. Когда я открываю https://localhost:5001/ в браузере, он говорит:

Веб-страница не найдена для веб-адреса: 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>();
            });
}

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

Примечание : я добавил строку app.UseHsts(); позже для экспериментов. Это также не работает без него.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...