找不到 JS 文件 -- 加载资源失败:服务器响应状态为 404 ()

Cannot find JS files -- Failed to load resource: the server responded with a status of 404 ()

我不知道如何让我的站点加载我的脚本。我在 _Layout.cshtml 文件的部分实施了这些脚本。

_Layout.cshtml

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"] - HighYieldSecondaryTradingApp</title>

<environment include="Development">
    <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.css" />
    <link rel="stylesheet" href="~/css/site.css" />
</environment>
<environment exclude="Development">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"
          asp-fallback-href="~/lib/bootstrap/dist/css/bootstrap.min.css"
          asp-fallback-test-class="sr-only" asp-fallback-test-property="position" asp-fallback-test-value="absolute" />
    <link rel="stylesheet" href="~/css/site.min.css" asp-append-version="true" />
</environment>
@*added by sean*@
<script src="~/Scripts/jquery-1.10.2.js"></script>
<script src="~/Scripts/sammy-0.7.4.js"></script>
<script src="~/Scripts/bootstrap.js"></script>
<script src="~/scripts/layout-routing.js"></script>
</head>

但是,对于我在底部添加的所有 4 个脚本,我在运行时遇到此错误:

Failed to load resource: the server responded with a status of 404 ()

下面是我的文件夹结构。

我引用的文件不正确吗?

Scripts 文件夹应位于 wwwroot 文件夹内,以便服务器找到它们。

要提供来自不同目录的静态文件,请使用:

app.UseStaticFiles(new StaticFileOptions()
{
    // Where the files are physicly located
    FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), @"Scripts")),
    // What relative url to serve the files from
    RequestPath = new PathString("/scripts")
});

在您的 Startup.cs Configure 方法中。

P.S 这不会改变服务器提供服务的位置,但会添加一个额外的目录来提供文件。