样式目录由于限制登录未能被加载
如果网站限制必须登录才能访问网站(例:后台系统),必须在根目录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中设置的路径别名:
发布后页面源码显示:
所以需要设置bundles目录为免登陆
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"));
.Net MVC4 发布后页面样式问题
最新推荐文章于 2022-04-10 22:34:58 发布