【问题标题】:MVC6 Default PageMVC6 默认页面
【发布时间】:2015-09-17 18:31:36
【问题描述】:

也许我只是醒了太多时间并且完全监督了一些事情,但我正在使用 MVC6 ASP.NET 5.0 来开发一个 AngularJS 网站。在我的 wwwroot 中,我有一个 index.html 页面,它工作得很好,但随后应用了更新,现在突然间我得到一个空白的白屏:开发人员工具告诉我:

加载资源失败:服务器响应状态为 404(未找到)

在我的创业公司中,我有以下内容:

public void Configure(IApplicationBuilder app)
{
    app.UseDefaultFiles(new Microsoft.AspNet.StaticFiles.DefaultFilesOptions() { DefaultFileNames = new[] { "index.html" } });
    app.UseMvc();
}

由于某种原因,我在调试时仍然得到一个空白页面并且没有加载任何内容。

【问题讨论】:

    标签: c# asp.net angularjs asp.net-mvc asp.net-core


    【解决方案1】:

    您还必须指定app.UseStaticFiles()From the docs:

    为了让您的 Web 应用程序在用户不必完全限定 URI 的情况下提供默认页面,请从 Startup.Configure 调用 UseDefaultFiles 扩展方法,如下所示。请注意,您还必须致电UseStaticFiles。这是因为UseDefaultFiles 是一个URL 重写器,它实际上并不提供文件。您仍然必须指定中间件(在这种情况下为UseStaticFiles)来提供文件。

    【讨论】:

    • 哦,我简直不敢相信我忘记了。是的,你完全正确。
    【解决方案2】:

    只是为了补充上面的答案:

    public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
    {
      ...
      // Serve the default file, if present.
      app.UseDefaultFiles();
      app.UseStaticFiles();
      ...
    }
    

    http://docs.asp.net/en/latest/fundamentals/static-files.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-04
      • 2012-10-23
      • 2014-05-13
      • 2023-03-03
      • 2012-07-15
      • 1970-01-01
      相关资源
      最近更新 更多