Javascript 找不到JS文件--加载资源失败:服务器响应状态为404()
我不知道如何让我的网站加载我的脚本。我在我的_Layout.cshtml文件的一节中实现了这些脚本 \u Layout.cshtmlJavascript 找不到JS文件--加载资源失败:服务器响应状态为404(),javascript,asp.net,model-view-controller,asp-net-core-spa-services,Javascript,Asp.net,Model View Controller,Asp Net Core Spa Services,我不知道如何让我的网站加载我的脚本。我在我的_Layout.cshtml文件的一节中实现了这些脚本 \u Layout.cshtml <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>@ViewData["T
<!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>
下面是我的文件夹结构
我引用的文件不正确吗?
脚本
文件夹应位于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.csConfigure
方法中
注意:这不会改变服务器的服务位置,但会添加一个额外的目录来服务文件
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")
});