index.html未显示为默认页面

DAG*_*DAG 45 c# asp.net-core

我在.NET Core中创建了一个空的 Web应用程序,wwwroot我的index.html没有加载为默认页面,只有在我明确调用它时才会加载.

这是我的project.json

{
  "version": "1.0.0-*",
  "compilationOptions": {
    "emitEntryPoint": true
  },

  "dependencies": {
    "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
    "Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final"
  },

  "commands": {
    "web": "Microsoft.AspNet.Server.Kestrel"
  },

  "frameworks": {
    "dnxcore50": { }
  },

  "exclude": [
    "wwwroot",
    "node_modules"
  ],
  "publishExclude": [
    "**.user",
    "**.vspscc"
  ]
}
Run Code Online (Sandbox Code Playgroud)

在这里我的启动:

public class Startup
{
    // This method gets called by the runtime. Use this method to add services to the container.
    // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
    public void ConfigureServices(IServiceCollection services)
    {
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app)
    {
        app.UseStaticFiles();
    }

    // Entry point for the application.
    public static void Main(string[] args) => WebApplication.Run<Startup>(args);
}
Run Code Online (Sandbox Code Playgroud)

And*_*yev 101

你必须添加

app.UseDefaultFiles();
Run Code Online (Sandbox Code Playgroud)

app.UseStaticFiles();Configure方法之前.

有关详细信息,请参阅文档

  • 这是其他信息.例如,要添加哪个库,以及哪个订单.http://www.talkingdotnet.com/make-index-html-startup-file-in-aspnet-core/ (4认同)