我正在尝试设置一个新的 Web 应用程序,我会在启动时加载 index.html(wwwroot 文件夹)。
在 ASP.NET 5 Beta 6 中,即使配置了 MVC,也只能通过 app.UseStaticFiles() 在 Configure 方法中调用来简单地完成。
现在,在 Beta 7 中(安装了 Web Tools 2015 Beta7),这不再有效 :( 我在许多文章中发现我也应该添加此调用:
app.UseDefaultFiles(new DefaultFilesOptions
{
DefaultFileNames = new [] { "index.html" }
});
但即便如此,index.html 仍未由框架提供。
这是我的 Startup.cs:
public class Startup
{
public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
{
var builder = new ConfigurationBuilder(appEnv.ApplicationBasePath)
.AddJsonFile("config.json")
.AddJsonFile($"config.{env.EnvironmentName}.json", optional: true);
if (env.IsDevelopment())
{
builder.AddUserSecrets();
}
builder.AddEnvironmentVariables();
Configuration = builder.Build();
}
public void ConfigureServices(IServiceCollection services)
{
// Add MVC services to the services container.
services.AddMvc();
}
public async void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
// Add static files to the request pipeline.
app.UseStaticFiles();
// Add default files to the request pipeline
app.UseDefaultFiles(new DefaultFilesOptions
{
DefaultFileNames = new [] { "index.html" }
});
// Add MVC to the request pipeline.
app.UseMvc();
}
}
有人知道如何解决这个问题吗?
最佳答案
它之前有效,因为默认情况下选择加入 IIS 失败,但现在您必须明确选择加入 as mentioned in the breaking changes in the announcements repo
关于c# - ASP.NET 5 Beta 7 (Web Tools 2015 Beta7) - wwwroot/index.html 未提供,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32839461/