小脚本是不是在头标记工作 [英] Scriptlet is not working in head tag

查看:105
本文介绍了小脚本是不是在头标记工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要版本号添加到CSS文件的生产环境不给力,用户每次preSS按Ctrl + F5新版本部署在督促服务器后,作为老版本的浏览器缓存下载新的CSS文件。

I want to add version number to CSS files for production environment not to force user every time press Ctrl+F5 to download new CSS files after new version is deployed in prod server as the old version is cached in browser.

我添加版本号作为查询字符串参数是这样的。

I'm adding build number as querystring param like this.

link href="Styles/jquery.Autocomplete.css?<%= Globals.BuildNumber %>" rel="stylesheet" type="text/css" 

,但输出是这

link href="../../Styles/jquery.Autocomplete.css?&lt;%= Globals.BuildNumber %>"

看起来是小脚本是不是在head标签的工作,因为这是在body标签的罚款。

Looks that scriptlet is not working in head tag, as this is fine in body tag.

推荐答案

它不记录任何地方,但你发现它不会出现的 HtmlHead 支持的嵌入式code块的。下面就来解决这个问题的方法。 (如果它不是很明显,它应该在code隐藏文件去):

It's not documented anywhere, but as you've found out it doesn't appear that HtmlHead supports embedded code blocks. Here's one way to get around that. (if it's not obvious, it should go in your code-behind file):

const int BuildNumber = 1;
protected override void OnLoad(EventArgs e) {
  base.OnLoad(e);
// add style sheet
  Header.Controls.Add(new Literal() {
    Text = string.Format(
      @"<link rel='stylesheet' type='text/css' href='custom.css?{0}' />",
      BuildNumber
    )
  });
}

这篇关于小脚本是不是在头标记工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆