【问题标题】:index.html not showing as default pageindex.html 未显示为默认页面
【发布时间】:2023-04-01 12:26:01
【问题描述】:

我在 .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);
}

【问题讨论】:

    标签: c# asp.net-core


    【解决方案1】:

    你必须添加

    app.UseDefaultFiles();
    

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

    更多详情请见documentation

    【讨论】:

    • 好一个!你说的对。它正在工作,订单起着重要作用,我不喜欢什么,但是......
    • 这里是附加信息。例如要添加哪个库,以及哪个顺序。 talkingdotnet.com/make-index-html-startup-file-in-aspnet-core
    • 有没有页面可以看到,什么时候需要调用哪个中间件?或者,只是谷歌这一切......
    • 对于我来说,问题的根源是在 UseMvc 之后使用 UseDefaultFiles
    • 处理a tutorial 我想添加一个html文件。我首先将foo.html 放在文件夹/pages/ 下,但它没有出现。将其移至 /wwwroot/ 即可。
    【解决方案2】:

    另一种方法是编辑您的 web.config 文件。添加新规则,满足您的需求。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-02-19
      • 2014-05-04
      • 2016-01-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-17
      相关资源
      最近更新 更多