我最近更改了操作系统,从 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 核心应用程序上。