.net MVC4 样式包提供 403
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13673759/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MVC4 style bundle giving 403
提问by Kieren Johnstone
When bundling/minification is enabled, some of my bundles seem to have an invalid URL in the browser (ending with a /), and IIS gives a 403 forbidden error, as if trying to list a folder's contents.
启用捆绑/缩小后,我的某些捆绑包在浏览器中似乎具有无效的 URL(以 / 结尾),并且 IIS 给出 403 禁止错误,就像试图列出文件夹的内容一样。
There's no difference in the way my bundles are set up - they are not .min.css, access permissions are correct etc.
我的包的设置方式没有区别 - 它们不是 .min.css,访问权限是正确的等等。
回答by Kieren Johnstone
My bundles were registered as paths which corresponded to an actual folder on the solution, e.g. ~/Content/forum.
我的包被注册为与解决方案上的实际文件夹相对应的路径,例如~/Content/forum.
This works fine when bundling is turned off (the bundle is included correctly!), but not when bundling is enabled.
这在捆绑关闭时工作正常(捆绑正确包含!),但在启用捆绑时不起作用。
The solution is to change the registered name of the bundle to not be the same as anything that exists in the file system.
解决方案是将捆绑包的注册名称更改为与文件系统中存在的任何名称不同。
回答by mohas
In my case bundle was specified as a directory @Scripts.Render("~/scripts")so IIS did not know how to serve the actual js file, I changed the bundle name to represent a javascript file @Scripts.Render("~/scripts.js")and that fixed it. The same was true for my style bundle.
在我的情况下,bundle 被指定为一个目录,@Scripts.Render("~/scripts")所以 IIS 不知道如何提供实际的 js 文件,我更改了 bundle 名称以表示一个 javascript 文件@Scripts.Render("~/scripts.js")并修复了它。我的风格包也是如此。
回答by Usman
The problem is the naming convention your bundle name should be
问题是您的包名称应该是命名约定
("bundles/css")
This solved my problem.
这解决了我的问题。

