【问题标题】:BundleConfig not rendered after publish in IIS在 IIS 中发布后未呈现 BundleConfig
【发布时间】:2015-07-06 17:36:29
【问题描述】:

我在服务器的 IIS 7 中发布我的 MVC 网站。当我检查页面源时,我发现它没有像在我的笔记本电脑中那样正确呈现。

这是在IIS服务器上发布后的页面源代码:

<title>Index - abc System</title>
<link href="/Content/css?v=_rLk6cMaTu8NrnGsCcMX7zjA8m5GS5kIRuTA39lx1hA1" rel="stylesheet"/>

<script src="/bundles/modernizr?v=wBEWDufH_8Md-Pbioxomt90vm6tJN2Pyy9u9zHtWsPo1"></script>

<script src="/bundles/jquery?v=FVs3ACwOLIVInrAl5sdzR2jrCDmVOWFbZMY6g6Q0ulE1"></script>

<script src="/bundles/bootstrap?v=Powlo484qpYf7E94XNxyY8F7N2GFx0uTQqXYUc9P62E1"></script>

<script src="/bundles/jqueryui?v=ZtBSbUDKlnEJoTEt91W1Sw3Wm7_cMVUFkutTVjnNqLk1"></script>


<!-- Script for menu -->
<script src="/Scripts/jqsimplemenu.js" type="text/javascript"></script>

这是我在笔记本电脑上测试时的页面源代码:

    <title>Index - abc System</title>
    <link href="/Content/jqueryui/jquery-ui.css" rel="stylesheet"/>
<link href="/Content/jqsimplemenu.css" rel="stylesheet"/>
<link href="/Content/bootstrap.css" rel="stylesheet"/>
<link href="/Content/Site.css" rel="stylesheet"/>
<link href="/Content/datepicker.css" rel="stylesheet"/>

    <script src="/Scripts/modernizr-2.6.2.js"></script>

    <script src="/Scripts/jquery-1.10.2.min.js"></script>

    <script src="/Scripts/respond.js"></script>
<script src="/Scripts/moment.js"></script>
<script src="/Scripts/bootstrap.js"></script>
<script src="/Scripts/bootstrap-datepicker.js"></script>

    <script src="/Scripts/jquery-ui.js"></script>


    <!-- Script for menu -->
    <script src="/Scripts/jqsimplemenu.js" type="text/javascript"></script>

这是 BundleConfig.cs 的代码:

public class BundleConfig
{
    // For more information on bundling, visit http://go.microsoft.com/fwlink/?LinkId=301862
    public static void RegisterBundles(BundleCollection bundles)
    {
    bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                "~/Scripts/jquery-{version}.js"));

    bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                "~/Scripts/jquery-1.10.2.min.js"));

    bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include(
    "~/Scripts/jquery-ui.js"));

    bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                "~/Scripts/jquery.validate*"));

    // Use the development version of Modernizr to develop with and learn from. Then, when you're
    // ready for production, use the build tool at http://modernizr.com to pick only the tests you need.
    bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
                "~/Scripts/modernizr-*"));

    bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
              "~/Scripts/respond.js",
              "~/Scripts/moment.js",
              "~/Scripts/bootstrap.js",
              "~/Scripts/bootstrap-datepicker.js"));

    bundles.Add(new StyleBundle("~/Content/css").Include(
               "~/Content/jqueryui/jquery-ui.css",
               "~/Content/jqsimplemenu.css",
                "~/Content/bootstrap.css",
               "~/Content/Site.css",
               "~/Content/datepicker.css"));
    }
}

这是我在服务器上发布后的页面结果:

这是预期的结果:

页面错误:

我能知道如何解决这个问题吗?谢谢。

【问题讨论】:

  • 已发布的版本被合并并缩小以提高性能。在调试时,它会将资源解包,因此更容易调试。
  • 它工作正常。没什么奇怪的。这就是调试模式关闭时捆绑包的工作方式。它合并包含在包中的文件以减少对服务器的调用。
  • 在发布后浏览我的网站时,似乎某些 css 无法加载..当我使用笔记本电脑运行时,我的网站看起来很难看..这就是为什么我认为这可能是因为渲染问题。 .在发布之前/之后有什么需要做的吗?
  • 首先,检查您是否没有找到任何 404 Not Found。您还有两个 jquery 捆绑包 - 您可以为 ~/Scripts/jquery-1.10.2.min.js 删除一个捆绑包。
  • 我没有找到任何 404 not found..是因为 ~/Scripts/jquery-1.10.2.min.js 吗?

标签: c# jquery asp.net-mvc iis server


【解决方案1】:

jqueryui 制作一个新包

bundles.Add(new StyleBundle("~/Content/jqueryui/css")
    .Include("~/Content/jqueryui/jquery-ui.css"));

bundles.Add(new StyleBundle("~/Content/css").Include(
        // "~/Content/jqueryui/jquery-ui.css",
           "~/Content/jqsimplemenu.css",
            "~/Content/bootstrap.css",
           "~/Content/Site.css",
           "~/Content/datepicker.css"));

StyleBundle 虚拟路径名应与项目的文件夹结构相匹配。样式规则可能包含对其他子目录的路径引用,当您的样式包名称与项目中的物理位置不匹配时,这些路径将无法解析。

.foo {
    background-image:url('../Images/foo.png');
}

【讨论】:

    【解决方案2】:

    在您的 web.config 中添加以下 &lt;system.webserver&gt; 节点。

    <system.webServer>
        <validation validateIntegratedModeConfiguration="false" />
        <modules runAllManagedModulesForAllRequests="true" />
    </system.webServer>
    

    希望这能解决您的问题。

    【讨论】:

      【解决方案3】:

      试试这个:

      1. 检查您的 web.config 配置并确保编译调试设置为 false

      2. 打开 IIS 配置 -> 身份验证 -> 右键单击​​匿名身份验证 -> 单击编辑 -> 选择应用程序池标识

      【讨论】:

        猜你喜欢
        • 2014-09-07
        • 2013-02-13
        • 2017-11-20
        • 2017-05-24
        • 2023-04-06
        • 1970-01-01
        • 1970-01-01
        • 2021-09-26
        • 1970-01-01
        相关资源
        最近更新 更多