【问题标题】:ASP.NET MVC Bundles for css are blank with OWIN用于 css 的 ASP.NET MVC 捆绑包在 OWIN 中为空白
【发布时间】:2017-10-16 08:34:16
【问题描述】:

我们最近将ASP.NET 5.2.3 应用程序移至OWIN 3.0.1 并遇到了捆绑问题。 *.js 正在适当地捆绑,但 *.css 捆绑包是空白的。

我在哪里可以从捆绑输出中查找更多详细信息以了解发生了什么?

代码结构


Login.cshtml

<head>
...
    @Html.RenderStyles("~/static/css/LoginPage")
...
</head>


BundleConfig.cs

using System.Web.Optimization;

namespace Foo.bar.Web.Bootstrapper {
  public class BundleConfig {
    public static void RegisterBundles(BundleCollection bundles) {
      bundles.UseCdn = true; //enable CDN support

      bundles
       .Add(new StyleBundle("~/static/css/LoginPage")
       .Include(
         "~/Static/css/login.css", 
         "~/Static/css/chosen.css")
       );
    }
  } 
}


Startup.cs

[assembly: OwinStartup(typeof(Startup))]
namespace Foo.Bar.Web.Bootstrapper {
    public class Startup {
        private IContainer container;
        public void Configuration(IAppBuilder app) {
            //Commenting/Uncommenting this makes no difference.
            //BundleConfig.RegisterBundles(BundleTable.Bundles);
        }
    }
}


Web.config

<modules runAllManagedModulesForAllRequests="true" />

【问题讨论】:

  • 首先,不要让你的包名与real文件夹冲突。换句话说,在 BundleConfig.cs 定义和 Login.cshtml 中将您的包名称更改为 ~/bundle/static/css/LoginPage。捆绑真的很痛苦
  • 您还可以确认您的网络标签中没有 404 错误。你怎么知道 CSS 是空白的?你是用F12工具看的吗?
  • 谢谢!是的,我正在使用 chrome 开发人员工具来检查捆绑包。我将尝试更改路径,并仔细检查网络选项卡。
  • 祝你好运,真的很痛苦。另请注意,当您处于调试模式时,它会自动关闭捆绑。这是我在我的网站运行良好时发现的,然后当我发布它时它完全失败了,因为捆绑不正确。看看她如何强制打开和关闭捆绑:stackoverflow.com/questions/16030905/…
  • 将路径更改为~/bundles/css/LoginPage 成功!请回复为答案,我会将其标记为答案。

标签: c# asp.net asp.net-mvc-5 owin bundling-and-minification


【解决方案1】:

首先要确保您的捆绑包名称不会与真实文件夹冲突。

换句话说,将您的捆绑包名称更改为~/bundle/static/css/LoginPage

在您的 BundleConfig.cs 定义和您的 Login.cshtml

【讨论】:

  • 谢谢!这样做填充了样式包,但是由于样式表中的相对路径,我遇到了许多 404。 >_正确的。干杯!
  • 哦,太好了!实际上,我自己在引导程序中的相对路径仍然存在问题 - 我不能使用字形图标。
猜你喜欢
  • 1970-01-01
  • 2015-08-07
  • 2021-11-16
  • 2017-12-19
  • 2013-08-06
  • 1970-01-01
  • 1970-01-01
  • 2017-03-25
  • 2018-06-21
相关资源
最近更新 更多