.Net MVC4 发布后页面样式问题

  1. 样式目录由于限制登录未能被加载
    如果网站限制必须登录才能访问网站(例:后台系统),必须在根目录Web.config配置资源目录无需登录.

     <!--页面权限控制-->
            <configuration>
              <location path="Content">
                <system.web>
                  <authorization>
                    <allow users="*"/>
                  </authorization>
                </system.web>
              </location>
              <location path="Scripts">
                <system.web>
                  <authorization>
                    <allow users="*"/>
                  </authorization>
                </system.web>
              </location>
    
              <!-- 注意:这个目录虽然项目没这个目录,但是由于BundleConfig中设置js集目录别名
              路径为bundles开头,所以发布后页面源码中路径也是bundles,所以要把这个目录设置为
              免登陆 -->
              <location path="bundles">
                <system.web>
                  <authorization>
                    <allow users="*"/>
                  </authorization>
                </system.web>
              </location>
              <location path="Images">
                <system.web>
                  <authorization>
                    <allow users="*"/>
                  </authorization>
                </system.web>
              </location>
            </configuration>

    注意: 由于BundleConfig中设置的问题,可能虽然js在Scripts目录中,但是设置的别名路径为其他名,则需要把这个别名路径第一个目录名设置为免登陆.

    Example:

    BundleConfig中设置的路径别名:
    BundleConfig中设置的路径别名

    发布后页面源码显示:
    发布后页面源码显示

    所以需要设置bundles目录为免登陆

  2. CSS样式出错
    查看页面源码,在css顶部出现以下提示:

        /* 未能缩小。正在返回未缩小的内容。
        (2,2-3): run-time warning JS1195: Expected expression: .
        (2,36-37): run-time warning JS1004: Expected ';': :
        (2,85-86): run-time warning JS1004: Expected ';': :
        (2,139-140): run-time warning JS1004: Expected ';': :
        (2,182-183): run-time warning JS1197: Too many errors. The file might not be a JavaScript file: :
     */

    查看系统源码发现BundleConfig中设置导致,css样式用了ScriptBundle导致压缩出错.

    正确格式:
    JS:

     bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                            "~/Scripts/jquery-{version}.js"));

    CSS:

    bundles.Add(new StyleBundle("~/Content/css/login").Include(
                    "~/Content/global.css",
                    "~/Content/login.css"));
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值