我正在使用Visual Studio Code中的命令dotnet run
运行DotNet Core 3.0应用程序。该应用程序成功运行,并在控制台中显示了URL https://localhost:5001/
和https://localhost:5000/
。当我在浏览器中打开https://localhost:5001/
时说:
找不到网址为https://localhost:5001/的网页 HTTP错误404
我运行https://localhost:5000/
时说:
该网站无法提供安全的连接。本地主机发送了无效的响应。
我确实运行了命令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();
行以进行实验。没有它也不行。