C# BundleConfig.cs MVC 4中缺少资源
我希望有人能抓住我错过的东西。我正在BundleConfig.cs中绑定我的javascript文件,它位于文件夹C# BundleConfig.cs MVC 4中缺少资源,c#,asp.net-mvc,bundle,C#,Asp.net Mvc,Bundle,我希望有人能抓住我错过的东西。我正在BundleConfig.cs中绑定我的javascript文件,它位于文件夹App\u Data中,如下所示 bundles.Add(new ScriptBundle("~/bundles/customScript").Include( "~/Views/Summary/storedata.js",
App\u Data
中,如下所示
bundles.Add(new ScriptBundle("~/bundles/customScript").Include(
"~/Views/Summary/storedata.js",
"~/Views/Summary/UploadData.js",
"~/Views/Summary/manipulateData.js"));
当我加载页面时,它说找不到资源。我仔细检查,路径是正确的。似乎无法加载视图中的资源。我在脚本文件夹中的库中有一些脚本可以加载
bundles.Add(new ScriptBundle("~/bundles/frameworkScripts").Include(
...
"~/Scripts/jquery.browser.min.js",
"~/Scripts/jquery.inputmask.bundle.js",
....
有什么我忘了检查的吗?也许能帮我指出正确的方向
更新
根据要求,我正在我的_Layout.cshtml中加载捆绑包,该捆绑包位于共享文件夹中,该文件夹位于视图文件夹中
<!DOCTYPE html>
<html>
<head>
<title>@ViewBag.Title</title>
<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<!-- Meta tag used for the finger gesture needed for swiping -->
<meta name="viewport" content="minimum-scale=1.0, maximum-scale=1.0, width=device-width, user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
@Styles.Render("~/Content/css")
@Styles.Render("~/Content/themes/base/css")
....
@Scripts.Render("~/bundles/frameworkScripts")
....
@Scripts.Render("~/bundles/customScript")
在标准ASP.Net MVC项目中,有两个Web.config文件(一个在根目录中,一个在视图目录中)。在第二个Web.config中,您将发现以下内容:
<httpHandlers>
<add path="*" verb="*"
type="System.Web.HttpNotFoundHandler"/>
</httpHandlers>
这将阻止服务器直接从“视图”文件夹或子文件夹提供任何文件。您可以使用以下代码替换它,但仍然是安全的:
<httpHandlers>
<add path="*.aspx" verb="*"
type="System.Web.HttpNotFoundHandler"/>
<add path="*.master" verb="*"
type="System.Web.HttpNotFoundHandler"/>
<add path="*.ascx" verb="*"
type="System.Web.HttpNotFoundHandler"/>
</httpHandlers>
这与以下事实有关:在ASP.NET MVC中,您无法通过URL访问视图
目录。所以你必须通过一个控制器才能看到一个视图。这就是路由的工作原理
因此,有一个脚本
目录(以及css、图像等的内容
目录)。如果每个视图有许多脚本,请在scripts
下为每个视图创建一个目录。您可以发布收到的完整错误吗?还有.cshtml中加载包的那一行?@AndrewCounts更新了帖子
<httpHandlers>
<add path="*.aspx" verb="*"
type="System.Web.HttpNotFoundHandler"/>
<add path="*.master" verb="*"
type="System.Web.HttpNotFoundHandler"/>
<add path="*.ascx" verb="*"
type="System.Web.HttpNotFoundHandler"/>
</httpHandlers>