我需要使用其他静态文件夹,所以我在Startup.cs中添加了app.UseStaticFiles(new StaticFileOptions {}):
namespace DailyAnlytics
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseBrowserLink();
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
}
app.Use(async (context, next) =>
{
//...
});
app.UseDefaultFiles();
app.UseStaticFiles();
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(
Path.Combine(Directory.GetCurrentDirectory(), "Mycustomfolder")),
RequestPath = "/Mycustomfolder"
});
app.UseMvc(routes =>
{
routes.MapRoute("default", "main{controller}/{action?}/{id?}");
});
}
}
}
如果发布目录中没有文件夹Mycustomfolder,则应用程序不会启动。如果该文件夹不存在,应如何使应用程序创建该文件夹?