MVC4风格的捆绑给出了403

在启用捆绑/缩小功能时,我的一些捆绑包在浏览器中似乎有一个无效的 URL (以/结尾) ,IIS 给出了一个403禁止错误,就好像试图列出一个文件夹的内容。

我的捆绑包的设置方式没有什么不同——它们没有不同。Css,访问权限是正确的等等。

29293 次浏览

My bundles were registered as paths which corresponded to an actual folder on the solution, e.g. ~/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.

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.

The problem is the naming convention your bundle name should be

("bundles/css")

This solved my problem.