c# - ASP.NET 5 Beta 7 (Web Tools 2015 Beta7) - wwwroot/index.html 未提供

标签 c# asp.net asp.net-mvc asp.net-core static-files

我正在尝试设置一个新的 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/

相关文章:

c# - Powershell 为 Func<T> 而不是 Action<T> 创建脚本 block

C#将一条记录从一个字典复制到另一个

c# - 上传后文件上传 Controller 不工作 - global.asax 上传后不触发

c# - 字典 : An item with the same key has already been added

c# - 为什么需要接口(interface)(用[ServiceContract]装饰)?

c# - 如何使用 System.Web.Security.MachineKey 跨网络保护和取消保护

asp.net - 如何使网站支持 Windows Live Writer?

asp.net - 从 Controller 的 HTTPGET 方法将动态变量传递给自定义操作过滤器

c# - 正则表达式不匹配任何html标签

c# - 新创建的MVC的_LogOnPartial文件