【问题标题】:linking Custom CSS to MVC6将自定义 CSS 链接到 MVC6
【发布时间】:2016-07-01 01:37:22
【问题描述】:
Failed to load resource: the server responded with a status of 404 (Not Found)

我在 Web 模式调试中使用 MVS 2015,并且我有

  app.UseStaticFiles();

而且我正在使用通用 HTTP 功能,所以出了什么问题?!

【问题讨论】:

  • 请提供错误请求的完整路径。您可能在错误的位置寻找资源。同样,没有完整的跟踪,很难查明问题

标签: css asp.net-mvc asp.net-core asp.net-core-mvc


【解决方案1】:

您的 project.json 中需要依赖项。

"Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final"

注意:默认情况下,ASP.net MVC 在wwwroot 文件夹中查找静态内容。但是,如果要更改它,则需要将其覆盖为Startup.cs

var staticContentFolder = new DirectoryInfo(env.WebRootPath).Parent;
if (staticContentFolder != null)
{
    app.UseStaticFiles(new StaticFileOptions()
    {
        FileProvider = new PhysicalFileProvider(
            Path.Combine(staticContentFolder.FullName, "Contents")),
        RequestPath = new PathString("/Contents")
    });
}

【讨论】:

  • 我有它,否则它会显示错误并且不会编译
  • 默认情况下,服务器会在“wwwroot”文件夹中查找静态文件。您将静态文件存储在哪里?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-03
  • 2012-04-20
  • 2011-02-27
  • 2013-04-21
  • 1970-01-01
相关资源
最近更新 更多