0

我正在使用 SharePoint Foundation 2010,并希望为某些页面或整个网站启用输出缓存。在 SharePoint Server 上,您有一种机制可以跨网站集启用页面输出缓存(它实际上是 ASP.NET 输出缓存)。在 SPF 上,您没有获得该功能 - 很公平。

那么如何启用输出缓存呢?在 ASP.NET 中,我只需添加一个页面指令 - 类似于 <%@ OutputCache Duration="30" %>。如果它在页面中,SharePoint 会引发错误。听起来它需要在代码中完成,也许会覆盖页面类?欢迎任何建议。

4

2 回答 2

0

您需要进入顶级网站集,在网站管理-> 网站集输出兑现-> 类似现金配置文件下有选项。在那里,您可以设置输出兑现和其他内容的配置文件。

于 2011-02-03T15:49:44.860 回答
0

你必须:

0 - 添加参数

<%@ OutputCache Duration="300" VaryByParam="*" Shared="True" VaryByCustom="x"  VaryByControl="hdnButtonToForceUpdateCacheIfYouWantOnClick" %>

1 - 扩展 SPHttpApplication、IVaryByCustomHandler。

public class MyCache: SPHttpApplication, IVaryByCustomHandler {
public override void Init()
        {
            base.Init();
            this.RegisterGetVaryByCustomStringHandler((Microsoft.SharePoint.ApplicationRuntime.IVaryByCustomHandler)this);
        }

        public string GetVaryByCustomString(HttpApplication app, HttpContext context, string custom)
        {
            StringBuilder sb = new StringBuilder();

 string[] strings = custom.Split(';');
            bool appended = false;
            foreach (string str in strings)
            {
                switch (str)
                {
                     case "x":
                         var xv= context.Request.Cookies.Get("x");
                        if (xv!= null)
                        {
                            sb.Append(xv.Value);
                        }

                        break;
                }
             }
             return sb.toString();
           }
   }

2 - 修改你的 global.asax 后,

<%@ Assembly Name="Microsoft.SharePoint"%>
<%@ Assembly Name="Energisa.Distribuidora.Webparts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e2d241931dc35e9d"%> 
<%@ Import Namespace="(Namespace).Webparts" %>
<%@ Application Language="C#" Inherits="(Namespace).MyCache" %>

查看更多信息:https ://msdn.microsoft.com/en-us/library/office/ms550239(v=office.14).aspx

于 2017-07-12T13:09:06.637 回答