Я не могу запустить свой Net Core 3.1 веб-сайт. При чтении файла stdout он говорит:
Необработанное исключение. System.InvalidOperationException: чтобы использовать UseSpaStaticFiles, вы должны сначала зарегистрировать ISpaStaticFileProvider у поставщика услуг, обычно вызывая services.AddSpaStaticFiles.
У меня никогда не было проблем с публикацией sh этого проекта и запуска. cs некоторое время не изменялся.
Может, я забыл внести какие-то изменения при миграции с 2.2 на 3.1?
public IServiceProvider ConfigureServices(IServiceCollection services)
{
services.AddAuthorization();
services.AddControllersWithViews();
services.AddMvcCore().AddRazorPages().AddRazorRuntimeCompilation();
services.AddJsReport(new LocalReporting().UseBinary(JsReportBinary.GetBinary()).KillRunningJsReportProcesses().AsUtility().Create());
services.ConfigureAuthentication(Configuration.GetValue<string>("Secret"));
services.AddAutoMapper(profileTypes);
services.ConfigureCors();
services.AddDbContext<TavoraContext>
(options => options.UseMySql(Configuration.GetConnectionString("DefaultConnection"),
mysqlOptions =>
{
mysqlOptions.ServerVersion(new Version(8, 0, 16), ServerType.MySql);
mysqlOptions.MigrationsAssembly("TavoraCore");
}));
// Autofac
var containerBuilder = new ContainerBuilder();
containerBuilder.RegisterModule<TavoraService.AutofacModule>();
containerBuilder.Populate(services);
var container = containerBuilder.Build();
// In production, the Angular files will be served from this directory
services.AddSpaStaticFiles(configuration =>
{
configuration.RootPath = "ClientApp/dist";
});
return new AutofacServiceProvider(container);
}
// 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();
//if (Regex.IsMatch(Configuration["ASPNETCORE_URLS"], @"https?://localhost[:/]")) // is local
//{
// string tsDefinitionsPath = "./ClientApp/src/app/models/";
// string tsDefinitionsFullPath = Path.Combine(env.ContentRootPath, tsDefinitionsPath);
// app.GenerateTypeScriptInterfaces(tsDefinitionsFullPath);
// app.UseCors(policy => policy.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin());
//}
}
else
{
app.UseExceptionHandler("/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseSpaStaticFiles();
app.UseStaticFiles(new StaticFileOptions()
{
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), @"Resources")),
RequestPath = new PathString("/Resources")
});
app.UseStaticFiles(new StaticFileOptions()
{
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), @"Themes")),
RequestPath = new PathString("/Themes")
});
app.UseRouting();
app.UseCors();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller}/{action=index}/{id?}");
});
app.UseSpa(spa =>
{
// To learn more about options for serving an Angular SPA from ASP.NET Core,
// see https://go.microsoft.com/fwlink/?linkid=864501
spa.Options.SourcePath = "ClientApp";
if (env.IsDevelopment())
{
spa.UseAngularCliServer(npmScript: "start");
}
});
}