ASP.NET MVC 发布到IIS样式缺失问题

使用VS2019开发asp.net MVC框架的时候,代码调试没有问题,在部署到IIS上的时候,通过浏览器提示获取不到相关的样式文件资源

有以下几种情况:1.在所在地址没有相关样式 ;   2.相关样式资源被压缩,在到IIS上面的时候无法正确读取到相关文件

第二种情况,要在BundleConfig.cs文件中配置相关的是否压缩配置文件。默认在调试阶段是不会压缩的

在部署到IIS上的时候记住加这个:

   BundleTable.EnableOptimizations = false;
整体代码如下
using System.Web;
using System.Web.Optimization;

namespace CHR_WMS.WebClient
{
    public class BundleConfig
    {
        // 有关捆绑的详细信息,请访问 https://go.microsoft.com/fwlink/?LinkId=301862
        public static void RegisterBundles(BundleCollection bundles)
        {
            bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                        "~/Scripts/jquery-{version}.js"));
            BundleTable.EnableOptimizations = false;
            bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                        "~/Scripts/jquery.validate*"));

            // 使用要用于开发和学习的 Modernizr 的开发版本。然后,当你做好
            // 生产准备就绪,请使用 https://modernizr.com 上的生成工具仅选择所需的测试。
            bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
                        "~/Scripts/modernizr-*"));

            bundles.Add(new StyleBundle("~/Content/BootStrap").Include(
                "~/Content/assets/plugin/bootstrap/css/bootstrap.min.css",
                "~/Content/assets/plugin/bootstrap/css/bootstrap-theme.min.css"));

            bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
                "~/ConTent/assets/scripts/jquery.min.js",
                "~/Content/assets/plugin/bootstrap/js/bootstrap.min.js"));

            bundles.Add(new StyleBundle("~/Content/LoginCss").Include(
                    
                ));

            bundles.Add(new ScriptBundle("~/bundles/define").Include(
                "~/ConTent/assets/scripts/jquery.min.js", 
                "~/ConTent/assets/scripts/modernizr.min.js", 
                "~/ConTent/assets/plugin/bootstrap/js/bootstrap.js",
                "~/Content/assets/plugin/treeview/bootstrap-treeview.js",
                "~/ConTent/assets/plugin/mCustomScrollbar/jquery.mCustomScrollbar.concat.min.js", 
                "~/ConTent/assets/plugin/nprogress/nprogress.js", 
                "~/ConTent/assets/plugin/sweet-alert/sweetalert-dev.js", 
                "~/ConTent/assets/plugin/waves/waves.js", 
                "~/ConTent/assets/scripts/main.js", 
                "~/ConTent/assets/plugin/modal/remodal/remodal.js", 
                "~/ConTent/assets/plugin/validator/validator.js"
                ));

            bundles.Add(new StyleBundle("~/ConTent/define").Include(
                "~/ConTent/assets/styles/style.css", 
                "~/ConTent/assets/fonts/material-design/css/materialdesignicons.css", 
                "~/ConTent/assets/plugin/mCustomScrollbar/jquery.mCustomScrollbar.min.css", 
                "~/ConTent/assets/plugin/waves/waves.css", 
                "~/ConTent/assets/plugin/sweet-alert/sweetalert.css", 
                "~/ConTent/assets/styles/style-dark.css", 
                "~/ConTent/assets/plugin/modal/remodal/remodal.css", 
                "~/ConTent/assets/plugin/modal/remodal/remodal-default-theme.css"
                ));

            bundles.Add(new StyleBundle("~/Content/Table").Include(
                "~/ConTent/assets/plugin/datatables/media/css/dataTables.bootstrap.css", 
                "~/ConTent/assets/plugin/datatables/extensions/Responsive/css/responsive.bootstrap.css"));
             
            bundles.Add(new ScriptBundle("~/bundles/Table").Include(
                "~/ConTent/assets/plugin/datatables/media/js/jquery.dataTables.js",
                "~/ConTent/assets/plugin/datatables/media/js/dataTables.bootstrap.js", 
                "~/ConTent/assets/plugin/datatables/extensions/Responsive/js/dataTables.responsive.js", 
                "~/ConTent/assets/plugin/datatables/extensions/Responsive/js/responsive.bootstrap.js", 
                "~/ConTent/assets/scripts/datatables.demo.js", 
                "~/Scripts/my-js.js", 
                "~/Scripts/ComponentControl.js", 
                "~/Scripts/FireManage.js"));

            bundles.Add(new StyleBundle("~/Content/DateTimePicker").Include("~/ConTent/assets/plugin/timepicker/bootstrap-timepicker.min.css", "~/ConTent/assets/plugin/datepicker/css/bootstrap-datepicker.css", "~/ConTent/assets/plugin/daterangepicker/daterangepicker.css", "~/ConTent/assets/plugin/jquery-ui/jquery-ui.css", "~/ConTent/assets/plugin/jquery-ui/jquery-ui.structure.css", "~/ConTent/assets/plugin/jquery-ui/jquery-ui.theme.css", "~/ConTent/bootstrap-switch/bootstrap3/bootstrap-switch.css", "~/ConTent/assets/plugin/toastr/toastr.css"));

            bundles.Add(new ScriptBundle("~/bundles/DateTimePicker").Include("~/ConTent/assets/plugin/timepicker/bootstrap-timepicker.min.js", "~/ConTent/assets/plugin/moment/moment.js", "~/ConTent/assets/plugin/datepicker/js/bootstrap-datepicker.js", "~/ConTent/assets/plugin/daterangepicker/daterangepicker.js", "~/ConTent/assets/scripts/form.demo.js", "~/ConTent/assets/plugin/jquery-ui/jquery-ui.js", "~/ConTent/assets/plugin/jquery-ui/jquery.ui.touch-punch.min.js","~/Scripts/bootstrap-switch.js", "~/ConTent/assets/plugin/toastr/toastr.min.js"));            
        }
    }
}

  

上一篇:fastadmin 移动端、pc端共用一套页面


下一篇:vue中引用图片