c# - index.html 未显示为默认页面

标签 c# asp.net-core

我在 .NET Core 中创建了一个 empty 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"
  ]
}

这是我的创业公司:

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);
}

最佳答案

你必须添加

app.UseDefaultFiles();

app.UseStaticFiles(); 之前,在 Configure 方法中。

参见 documentation了解更多详情。

关于c# - index.html 未显示为默认页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35777631/

相关文章:

c# - 如何使用 System.Text.Json API 将流反序列化为对象

c# - 接口(interface)与 SVG 曲线的区分联合

asp.net-core - 如何在ASP.NET Core中使用JWT授权重定向到401上的登录页面

json - 如何在 ASP.NET 5.0 中为 log4net(或任何其他第三方库)添加配置

c# - 将字符串替换为 DataTable 的 DataColumn 中的另一个字符串

c# - 如何在不使用测量工作室的情况下将模拟测量从 National Instruments USB 6008 获取到 C# 应用程序中?

angular - IdentityServer4 + ASP.NET 核心 API + Angular : Login/authentication

c# - 请求和操作之间的 Asp.net 核心中间件路由延迟

asp.net-mvc - 如何在 ASP.NET Core 中启用 ClientCache

c# - Ajax处理中的"Invalid JSON primitive"