问题描述
我正在尝试对一些 .css 和 .js 文件使用包缩小.我的捆绑配置如下:
I'm trying to use bundle minification for some .css and .js files. My bundle config is the following:
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/Modernizr").Include(
"~/Scripts/modernizr.js"
));
bundles.Add(new StyleBundle("~/TemplateContent").Include(
"~/Content/bootstrap.css",
"~/Content/bootstrap-responsive.css",
"~/Content/prettyPhoto.css",
"~/Content/prettify.css",
"~/Content/flexslider.css",
"~/Content/iview.css",
"~/Content/style.css",
"~/Content/default.css"
));
bundles.Add(new StyleBundle("~/AppContent").Include(
"~/Content/bootstrap-tablesorter.css",
"~/Content/animate.css",
"~/Content/font-awesome.css",
"~/Content/jcarousel.css",
"~/Conten/overwrite.css",
"~/Content/sequence.css",
"~/Content/sequence.ie.css",
//more styles
));
bundles.Add(new ScriptBundle("~/TemplateScripts").Include(
"~/Scripts/modernizr-*",
"~/Scripts/jquery.js",
"~/Scripts/raphael.js",
"~/Scripts/jquery.easing.1.3.js",
"~/Scripts/bootstrap.js",
"~/Scripts/google-code-prettify/prettify.js",
"~/Scripts/jquery.elastislide.js",
"~/Scripts/jquery.tweet.js",
"~/Scripts/jquery.prettyPhoto.js",
"~/Scripts/jquery.flexslider.js",
"~/Scripts/iview.js",
"~/Scripts/jquery-hover-effect.js",
"~/Scripts/animate.js",
"~/Scripts/custom.js"
));
bundles.Add(new ScriptBundle("~/AppScripts").Include(
"~/Scripts/jquery.ticker.js",
"~/Scripts/jquery.contenthover.js",
"~/Scripts/jquery-ui-1.10.3.js",
"~/Scripts/datetimepicker.js",
"~/Scripts/jquery.metadata.js",
//more scripts
));
BundleTable.EnableOptimizations = true;
}
当我将应用程序发布到服务器(godaddy 共享虚拟主机)时,问题发生了,我确实得到了缩小的输出,但在这些输出上出现了 403 错误.
The problem happens when I publish the app to a server (godaddy shared web hosting), I do get a minified output, but I get 403 errors on those outputs.
如果我设置
BundleTable.EnableOptimizations = false;
文件未缩小,但页面行为正确.
The files are not minified but the page has the correct behavior.
推荐答案
原来是 ASP.NET 表单身份验证.根据this,捆绑包的名称不应是现有目录.好吧,表单身份验证拒绝访问 web.config 中不允许的那些目录.
Turns out it was ASP.NET form authentication. As according to this, the name of the bundle should not be an existing directory. And well, forms authentication denies access to those directories that are not allowed int the web.config.
我不知道这些包会创建自己的目录,所以我基本上为这些目录添加了位置标记(即使它们实际上不在解决方案中).
I did not know that the bundles create their own directory, so I basically added the location tag for those directories (even though they are not physically in the solution).
所以基本上...
对于之前的所有包名称,我添加了~/bundles/",然后在 web.config 中创建了以下位置标记:
For all of the previous bundles names, I added "~/bundles/" and then created the following location tag in the web.config:
<location path="bundles">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
这篇关于发布 WebForms 应用程序时捆绑缩小不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!