因此,我正在努力学习如何在 MVC 中使用脚本捆绑实用程序,但我遇到了一个问题——我不太了解如何为每个 ScriptBundle 对象构建虚拟路径。例如,当使用允许指定 CDN 的构造函数时,我有以下设置
在 Global.asax 中,我有以下电话
BundleConfig.RegisterBundles(BundleTable.Bundles);
然后在 BundleConfig 类中,我有
public static void RegisterBundles(BundleCollection bundles)
{
//add link to jquery on the CDN
const string jqueryCdnPath = @"http://code.jquery.com/jquery-2.1.0.min.js";
const string jqueryUiCdnPath = @"http://code.jquery.com/ui/1.10.4/jquery-ui.min.js";
const string jqueryColorCdnPath = @"http://code.jquery.com/color/jquery.color-2.1.2.min.js";
var jqueryQunitCdnPath = @"http://code.jquery.com/qunit/qunit-1.14.0.js";
bundles.Add(new ScriptBundle("~/Resources/Scripts/js/jquery", jqueryCdnPath)
.Include("~/Resources/Scripts/js/jquery/jquery-{version}.js"));
bundles.Add(new ScriptBundle("~/Resources/Scripts/js/jquery/ui", jqueryUiCdnPath)
.Include("~/Resources/Scripts/js/jquery/ui/j-{version}/jquery-ui.js"));
bundles.Add(new ScriptBundle("~/Resources/Scripts/js/jquery/color", jqueryColorCdnPath)
.Include("~/Resources/Scripts/js/jquery/color/jquery.color-{version}.js"));
bundles.Add(new ScriptBundle("~/Resources/Scripts/js/jquery/jqueryval")
.Include("~/Resources/Scripts/js/jquery.unobtrusive*", "~/Resources/Scripts/js/jquery.validate*"));
}
但是,当我构建并运行我的页面时,我在第一次添加时收到以下错误消息。
**Directory does not exist.
Parameter name: directoryVirtualPath
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: Directory does not exist.
Parameter name: directoryVirtualPath
Source File: c:\######.Web\App_Start\BundleConfig.cs Line: 30
Stack Trace:
[ArgumentException: Directory does not exist.
Parameter name: directoryVirtualPath]
System.Web.Optimization.Bundle.Include(String virtualPath, IItemTransform[] transforms) +90
Network.Web.BundleConfig.RegisterBundles(BundleCollection bundles) inc:\######.Web.Web\App_Start\BundleConfig.cs:30
Network.Web.MvcApplication.Application_Start() in c:\######.Web\Global.asax.cs:27
[HttpException (0x80004005): Directory does not exist.
Parameter name: directoryVirtualPath]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +9936761
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +118
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +336
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +296
[HttpException (0x80004005): Directory does not exist.
Parameter name: directoryVirtualPath]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9915300
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254**
是否有我可能在这里遗漏的配置要求?我的路径格式错误吗?
在此先感谢您的帮助。