C# 包在我的服务器上不工作
C# Bundles not working on my server
我知道有很多关于这个主题的话题,但我想我已经全部阅读了。由于我仍然无法解决我的问题,所以我写了我自己的主题。
这是我的 BundleConfig 文件:
public static void RegisterBundles(BundleCollection bundles)
{
var scriptBundle = new ScriptBundle("~/bundles/layoutJS")
.Include(
"~/Scripts/jquery-1.11.2.js"
, "~/Scripts/jquery-ui.js"
, "~/Scripts/jquery.stellar.js"
, "~/Scripts/jquery.velocity.js"
, "~/Scripts/jquery.tubular.1.0.custom.js"
, "~/Scripts/helper.js"
, "~/Scripts/Style/Plugins/popup.js"
, "~/Scripts/Style/Plugins/select.js"
, "~/Scripts/Style/Plugins/jQuery/cnil.js"
, "~/Scripts/Style/layout.js"
);
scriptBundle.Orderer = new BundleOrderer();
bundles.Add(scriptBundle);
var cssBundle = new StyleBundle("~/bundles/layoutCSS")
.Include(
"~/Content/Style/Font-Awesome/font-awesome.css"
, "~/Content/Style/Jquery-ui/jquery-ui.css"
, "~/Content/Style/Jquery-ui/jquery-ui.structure.css"
, "~/Content/Style/Jquery-ui/jquery-ui.theme.css"
);
cssBundle.Orderer = new BundleOrderer();
bundles.Add(cssBundle);
}
我没有这条线:
BundleTable.EnableOptimizations = true;
因为我有 web.config 可以解决问题。这是我的一部分 web.config(仅在本地使用)
<system.web>
<compilation targetFramework="4.5.1" debug="true" />
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
这是用于我的舞台服务器的 web.release.config :
<system.web xdt:Transform="Replace">
<compilation targetFramework="4.5.1" debug="false"/>
</system.web>
最后在我的 _layout.cshtml 中我渲染了我的包 :
@Styles.Render("~/bundles/layoutCSS")
@Scripts.Render("~/bundles/layoutJS")
所以我认为我还好但是...不是 :( 如果我 运行 我的网站在本地,无论是调试还是发布配置,行为都正常,我所有的脚本和样式都是出现并且 chrome 控制台中没有错误。
但是当我在我的服务器上部署时...它坏了:
- 首先我在源代码中没有捆绑包的版本号
- 其次,显然我每个捆绑包都有一个 404...
我服务器的 IIS 有什么需要做的吗?
我错过了什么吗?
非常感谢您以后的回答!
编辑:捆绑注册:
protected void Application_Start()
{
Bootstraper.Run();
var unitOfWork = (IUnitOfWork)Bootstraper.GetInstance<IUnitOfWork>();
var cache = (ICacheManager) Bootstraper.GetInstance<ICacheManager>();
MvcHandler.DisableMvcResponseHeader = true;
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes, unitOfWork.RouteRepository, cache);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
更新您的 web.config,更改 <system.webServer>
部分的以下内容:
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<remove name="BundleModule" />
<add name="BundleModule" type="System.Web.Optimization.BundleModule" />
</modules>
</system.webServer>
啊啊啊啊啊啊,其实还好。唯一的问题是我的脚本文件夹中有一个空目录,所以它没有部署......不幸的是,我在制作一些包的模式中有一个关于这个目录的规则。所以它破坏了所有其他捆绑包。
感谢@Vivien Chevallier 的回答。
我知道有很多关于这个主题的话题,但我想我已经全部阅读了。由于我仍然无法解决我的问题,所以我写了我自己的主题。
这是我的 BundleConfig 文件:
public static void RegisterBundles(BundleCollection bundles)
{
var scriptBundle = new ScriptBundle("~/bundles/layoutJS")
.Include(
"~/Scripts/jquery-1.11.2.js"
, "~/Scripts/jquery-ui.js"
, "~/Scripts/jquery.stellar.js"
, "~/Scripts/jquery.velocity.js"
, "~/Scripts/jquery.tubular.1.0.custom.js"
, "~/Scripts/helper.js"
, "~/Scripts/Style/Plugins/popup.js"
, "~/Scripts/Style/Plugins/select.js"
, "~/Scripts/Style/Plugins/jQuery/cnil.js"
, "~/Scripts/Style/layout.js"
);
scriptBundle.Orderer = new BundleOrderer();
bundles.Add(scriptBundle);
var cssBundle = new StyleBundle("~/bundles/layoutCSS")
.Include(
"~/Content/Style/Font-Awesome/font-awesome.css"
, "~/Content/Style/Jquery-ui/jquery-ui.css"
, "~/Content/Style/Jquery-ui/jquery-ui.structure.css"
, "~/Content/Style/Jquery-ui/jquery-ui.theme.css"
);
cssBundle.Orderer = new BundleOrderer();
bundles.Add(cssBundle);
}
我没有这条线:
BundleTable.EnableOptimizations = true;
因为我有 web.config 可以解决问题。这是我的一部分 web.config(仅在本地使用)
<system.web>
<compilation targetFramework="4.5.1" debug="true" />
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
这是用于我的舞台服务器的 web.release.config :
<system.web xdt:Transform="Replace">
<compilation targetFramework="4.5.1" debug="false"/>
</system.web>
最后在我的 _layout.cshtml 中我渲染了我的包 :
@Styles.Render("~/bundles/layoutCSS")
@Scripts.Render("~/bundles/layoutJS")
所以我认为我还好但是...不是 :( 如果我 运行 我的网站在本地,无论是调试还是发布配置,行为都正常,我所有的脚本和样式都是出现并且 chrome 控制台中没有错误。
但是当我在我的服务器上部署时...它坏了: - 首先我在源代码中没有捆绑包的版本号 - 其次,显然我每个捆绑包都有一个 404...
我服务器的 IIS 有什么需要做的吗? 我错过了什么吗?
非常感谢您以后的回答!
编辑:捆绑注册:
protected void Application_Start()
{
Bootstraper.Run();
var unitOfWork = (IUnitOfWork)Bootstraper.GetInstance<IUnitOfWork>();
var cache = (ICacheManager) Bootstraper.GetInstance<ICacheManager>();
MvcHandler.DisableMvcResponseHeader = true;
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes, unitOfWork.RouteRepository, cache);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
更新您的 web.config,更改 <system.webServer>
部分的以下内容:
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<remove name="BundleModule" />
<add name="BundleModule" type="System.Web.Optimization.BundleModule" />
</modules>
</system.webServer>
啊啊啊啊啊啊,其实还好。唯一的问题是我的脚本文件夹中有一个空目录,所以它没有部署......不幸的是,我在制作一些包的模式中有一个关于这个目录的规则。所以它破坏了所有其他捆绑包。
感谢@Vivien Chevallier 的回答。