我正在尝试设置新的Web应用程序,并且我会在启动时加载index.html(wwwroot文件夹)。
在ASP.NET 5 Beta 6中,即使配置了MVC,也只能使用Configure方法中的 app.UseStaticFiles()调用完成此操作。
现在,在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();
}
}
有人知道如何解决这个问题吗?
答案 0 :(得分:0)
之前有效,因为默认情况下选择了IIS,但现在您必须明确选择as mentioned in the breaking changes in the announcements repo