Ben*_*erg 0 .net asp.net sharepoint
我的客户测试环境中有一个 SharePoint 2013 Server。它通过名为Net Scaler的缓存实例进行过滤,该实例可以很好地将相同的文件传递给不同的客户端。问题是它不检查文件是否是新的 - 它只是推出它得到的文件。
添加诸如之类的 css 变量styles.css?ver=1000可以解决问题,并且 Net Scaler 会将其视为新文件。但是,我很难在每个页面请求上使其唯一。
由于这是 SharePoint 2013,因此我不允许编辑后台代码,并且仅限于 .master 文件。我尝试过不同的标记,但没有任何效果符合我的预期。
这是我迄今为止的尝试,但没有达到预期效果。
<SharePoint:CssRegistration 
name="/_catalogs/masterpage/Customer/Style/ResponsiveMaster.css?ver=
<%= DateTime.Now.ToString() %>" runat="server" after="SharepointCssFile" />
<!-- or -->
<link rel="stylesheet" type="text/css"
href="/_catalogs/masterpage/Customer/Style/ResponsiveMaster.css?ver=
<%= DateTime.Now.ToString() %>"  />
我什至尝试使用这篇文章中的内联 JavaScript 加载css 文件 How to load up CSS files using Javascript? :
<script type="text/javascript">
    //<![CDATA[ 
        var $ = document; // shortcut
        var timestamp = Date.now();
        var cssId = '/_catalogs/masterpage/Customer/Style/ResponsiveMaster.css?ver=' + timestamp;  
        // you could encode the css path itself to generate id..
        if (!$.getElementById(cssId))
        {
            var head  = $.getElementsByTagName('head')[0];
            var link  = $.createElement('link');
            link.id   = cssId;
            link.rel  = 'stylesheet';
            link.type = 'text/css';
            link.href = '/_catalogs/masterpage/Customer/Style/ResponsiveMaster.css?ver=' + timestamp;
            link.media = 'all';
            head.appendChild(link);
        }
    //]]>
</script>
但那里也没有运气。
将以下标记放置在 .Master 页面中:
<link rel="stylesheet" 
       href=<%="'css/main.css?v="+ DateTime.Now.ToString("yyyyMMddhhmmss") +"'"%> />
要允许在共享点中使用内联代码块,根据此博客文章,您需要修改 web.config。将 PageParser 部分替换为以下代码:
<PageParserPaths >
  <PageParserPath VirtualPath="/*" CompilationMode="Always"   
                  AllowServerSideScript="true" IncludeSubFolders="true" />
</PageParserPaths>
将在浏览器中产生以下输出:
   <link rel="stylesheet"  href='css/main.css?v=20140123113734' />