无法加载资源:403禁止使用.js优化当我使用BundleTable.EnableOptimizations=true激活优化时,我已经安装了打包的Install-PackageMicrosoft.AspNet.Web.Optimization;403(禁止访问)http://localhost:22773/Content/themes/elevation/v=gnDLBbf1VVRuQDXtIYn1q0P3ICZG7oiwwgxPRbaLvqI1有人知道我做错了什么吗?—BundleConfig信息——————————publicclassBundleConfig{publicstaticvoidRegisterBundles(BundleCollectionbundles){BundleTable.EnableOptimizations=true;bundles.Add(newScriptBundle("~/bundles/myJquery").Include("~/Scripts/jquery-1.9.1.js","~/Scripts/jquery-ui-1.10.1.custom.js","~/Scripts/jquery.signalR-1.0.1.js","~/Scripts/signalr-hubs.js","~/Scripts/Controls/Select/Simple/jquery.ui.selectmenu.js"));bundles.Add(newScriptBundle("~/bundles/shared").Include("~/Scripts/global/prototypes.js","~/Scripts/global/mathutil.js","~/Scripts/global/elevationevents.js"));捆es.Add(newScriptBundle("~/bundles/core").Include("~/Scripts/elevation/core/sys.config.js","~/Scripts/elevation/core/bays.js","~/Scripts/elevation/core/door.js","~/Scripts/elevation/core/horiziontal.js","~/Scripts/elevation/core/vertical.js"));bundles.Add(newStyleBundle("~/Content/themes/elevation").Include("~/Content/themes/dialogs/dialogs.css","~/Content/themes/social/ac/acSocial.css","~/Content/themes/elevation/elevation.css"));}}——————————–我还没有想到这一点——————我在windows7操作系统上使用2013.net和iis8这是我最新的错误,我不能让我的解决方案退出调试模式,因为如果我这样做,我会在下面收到该错误HTTP错误403.14-禁止Web服务器配置为不列出此目录的内容。最可能的原因:没有为请求的URL配置默认文档,并且服务器上没有启用目录浏览。您可以尝试的事情:如果您不想启用目录浏览,请确保配置了默认文档并且该文件存在。启用目录浏览。转到IISExpress安装目录。运行appcmdsetconfig/section:system.webServer/directoryBrowse/enabled:true以在服务器级别启用目录浏览。运行appcmdsetconfig["SITE_NAME"]/section:system.webServer/directoryBrowse/enabled:true以在站点级别启用目录浏览。验证站点或应用程序配置文件中的configuration/system.webServer/directoryBrowse@enabled属性是否设置为true。详细错误信息:ModuleDirectoryListingModuleNotificationExecuteRequestHandlerHandlerStaticFileErrorCode0x00000000RequestedURLhttp://localhost:1499/Content/themes/elevation/?v=aukmuLTC3g_fDko3eWmzqq7A8miRqgsJKXA2GO3w-pg1PhysicalPathc:usersadministratordocumentsvisualstudio2013ProjectsAlumCloudAlumCloudContentthemeselevationLogonMethodAnonymousLogonUserAnonymousRequestTracingDirectoryC:UsersAdministratorDocumentsIISExpressTraceLogFilesALUMCLOUD(3)MoreInformation:如果未在URL中指定文档,未为网站或应用程序指定默认文档,并且未为网站或应用程序启用目录列表,则会发生此错误。可以故意禁用此设置以保护服务器内容。查看更多信息?这是iis8在不处于产生错误的调试模式时创建的urlhttp://localhost:1499/Content/themes/elevation/?v=aukmuLTC3g_fDko3eWmzqq7A8miRqgsJKXA2GO3w-pg1这是实际的.css返回文件没有任何错误的urlhttp://localhost:1499/Content/themes/elevation/elevation.css只是有同样的问题在我的例子中,解决方案是给内容包一个不同的名称。我想这是因为IIS拦截了请求,把包名当成了目录,由于Content文件夹确实存在,所以返回了forbidden错误。因此,您可以将~/Content/themes/elevation重命名为~/css/themes/elevationbundles.Add(newStyleBundle("~/css/themes/elevation").Include("~/Content/themes/dialogs/dialogs.css","~/Content/themes/social/ac/acSocial.css","~/Content/themes/elevation/elevation.css"));另外,不要忘记调整标记/母版页以使用修改后的包名称,即然后将位置指令添加到web.config以允许访问包:希望这有帮助。您必须使包名称类似于资源的实际路径。使用debug='false'或BundleTable.EnableOptimizations=true;编译时,系统找不到资源BundleTable.EnableOptimizations=true;。因为系统使用包名来生成资源链接。所以你的包名应该是这样的–bundles.Add(newScriptBundle("~/Scripts/myJquery").Include("~/Scripts/jquery-1.9.1.js","~/Scripts/jquery-ui-1.10.1.custom.js","~/Scripts/jquery.signalR-1.0.1.js","~/Scripts/signalr-hubs.js","~/Scripts/Controls/Select/Simple/jquery.ui.selectmenu.js"));bundles.Add(newScriptBundle("~/Scripts/global/shared").Include("~/Scripts/global/prototypes.js","~/Scripts/global/mathutil.js","~/Scripts/global/elevationevents.js"));bundles.Add(newScriptBundle("~/Scripts/elevation/core/core").Include("~/Scripts/elevation/core/sys.config.js","~/Scripts/elevation/core/bays.js","~/Scripts/elevation/core/door.js","~/Scripts/elevation/core/horiziontal.js","~/Scripts/elevation/core/vertical.js"));bundles.Add(newStyleBundle("~/Content/themes/dialogs/dialog").Include("~/Content/themes/dialogs/dialogs.css"));bundles.Add(newStyleBundle("~/Content/themes/social/ac/ac").Include("~/Content/themes/social/ac/acSocial.css"));编辑编辑这将适用于IIS6。但是对于IIS7或7.5,解决方案是其他的我在IIS7.5中部署应用程序时遇到了同样的问题。解决方案是在IIS7.5上安装ASP.NETMVC4中讨论的修补程序,返回404。与在WindowsServer2008上运行IIS7的无扩展路由映射和ASP.NET4.5MVC4无关你确定吗它必须是/elev/v=gn...但不是/themes/elevation吗?v=gnDLBbf(带?)?如接受的答案中所述,您指定的包名称与实际存在的文件夹冲突。例如,考虑以下内容:bundles.Add(newStyleBundle("~/content/epic").Include("~/Content/Epic/StickyFooter.css"));会给我OP指出的相同类型的错误:{myURL}/content/epic/?v=YTZL7Up6r-0uQblkv6unjKN5Nfb3uwtE0bPz9nxbjDc1加载失败这是因为优化器试图创建的虚拟路径(内容/史诗)恰好是我站点中的现有文件夹路径(我有一个名为“content”的文件夹,其中包含一个名为“epic”的文件夹)。如果我将包路径更改为以下内容:bundles.Add(newStyleBundle("~/content/epic2").Include("~/Content/Epic/StickyFooter.css"));问题不再存在,因为我的“内容”文件夹中没有名为“epic2”的文件夹。与接受的答案相反,我建议不要将包目录(例如“~/Content/a/b/”)更改为“~/css/a/b”,因为如果样式表包含相对引用,则另一个潜在问题外部文件.考虑我的AjaxLoadAnimation.css样式表,它包含以下片段:...background:rgba(255,255,255,.5)url('images/spin.gif')50%50%no-repeat;...为确保引用适用于优化和非优化编译,请确保包的路径与包中每个项目的路径相匹配。如果您的样式表位于~/Content/my/path,那么您的包应该以~/Content/my/path开头。为避免OP的问题,只需确保名称(在我的例子中为“sharedcss”)不与现有文件夹冲突。bundles.Add(newStyleBundle("~/Content/my/path/sharedcss").Include("~/Content/my/path/bootstrap.css","~/Content/my/path/font-awesome.css","~/Content/my/path/AjaxLoadAnimation.css"));希望这可以使其他人免于同样的挫败感。以上为C#学习教程:Unabletoloadresource:403Forbiddentouse.js优化所有分享内容。如果对大家有用,需要进一步了解C#学习教程,希望大家多多关注。本文收集自网络,不代表立场,如涉及侵权,请点击右边联系管理员删除。如需转载请注明出处:
