【问题标题】:Clean up html output for anonymous users in SharePoint 2010在 SharePoint 2010 中为匿名用户清理 html 输出
【发布时间】:2012-02-01 09:19:40
【问题描述】:

我正在使用 SharePoint 2010 构建一个面向 Internet 的大型网站,我现在正在为匿名用户优化该网站。 当我查看起始页的 html 源代码时,我发现 SharePoint 的各种 ootb 组件向页面添加了许多不必要的内容。 (至少匿名用户不需要它们,因为我们使用的是完全自定义的品牌。)

一些例子:

在头上:

<style type="text/css"> 
.ctl00_PlaceHolderOuterWrap_DialogPlaceHolder_PlaceHolderOuterMain_TopWebPartZone_0 { border-color:Black;border-width:1px;border-style:Solid; }
.ctl00_PlaceHolderOuterWrap_DialogPlaceHolder_PlaceHolderOuterMain_LeftWebPartZone_0 { border-color:Black;border-width:1px;border-style:Solid; }
.ctl00_PlaceHolderOuterWrap_DialogPlaceHolder_PlaceHolderOuterMain_RightWebPartZone_0 { border-color:Black;border-width:1px;border-style:Solid; }
.ctl00_PlaceHolderOuterWrap_DialogPlaceHolder_PlaceHolderOuterMain_ctl01_SocialWebPartZone_0 { border-color:Black;border-width:1px;border-style:Solid; }
.ctl00_wpz_0 { border-color:Black;border-width:1px;border-style:Solid; }

在身体顶部:

<script type="text/javascript"> 
//<![CDATA[
var MSOWebPartPageFormName = 'aspnetForm';
var g_presenceEnabled = true;
var g_wsaEnabled = false;
var g_wsaLCID = 1033;
var g_wsaSiteTemplateId = 'XXX#1';
var g_wsaListTemplateId = 850;
var _fV4UI=true;var _spPageContextInfo = {webServerRelativeUrl: "\u002fen-gb", webLanguage: 1033, currentLanguage: 1033, webUIVersion:4,pageListId:"{28b31ecf-221c-4a5f-94e2-6b97af0cfd61}",pageItemId:1, alertsEnabled:true, siteServerRelativeUrl: "\u002f", allowSilverlightPrompt:'True'};//]]>
</script>
<script type="text/javascript"> 
<!--
var L_Menu_BaseUrl="/en-gb";
var L_Menu_LCID="1033";
var L_Menu_SiteTheme="";
//-->
</script>
<script type="text/javascript"> 
//<![CDATA[
document.onreadystatechange=fnRemoveAllStatus; function fnRemoveAllStatus()    {removeAllStatus(true)};var _spWebPartComponents = new Object();//]]>
</script>

以及页面底部附近的许多其他内容,例如 javascript 函数等。

有人试过删除所有这些东西吗?

我正在寻找尽可能干净的方式,在 http-module 过滤器中解析 html 并不是很吸引人。

谢谢!

【问题讨论】:

    标签: html sharepoint optimization sharepoint-2010


    【解决方案1】:

    我的建议是为匿名用户使用专门的母版页(并删除您不需要的所有用户/服务器控件),以消除尽可能多的混乱。您可以让您的页面布局实现一个基类,在该基类中,您可以在初始化阶段分配您自己的仅匿名母版页。

    另一种解决方案是将负责杂乱/不需要的 html 的 Web 控件/组件包装在仅经过身份验证的控件模板中。

    /// <summary>
    /// Base Abstract control for conditionally (permissions, querystring, audience, anonymous, etc.) visible content 
    /// </summary>
    [ParseChildren(true)]
    public abstract class ConditionallyVisibleControl : Control
    {
        public ITemplate ContentTemplate { get; set; }
        public abstract bool ShouldBeVisible { get; }
    
        protected override void CreateChildControls()
        {
            base.CreateChildControls();
    
            if (ShouldBeVisible && ContentTemplate != null)
            {
                Control container = new Control();
                ContentTemplate.InstantiateIn(container);
                Controls.Add(container);
            }
        }
    }
    

    他们有类似的东西

    /// <summary>
    /// Hide some content to anonymous user
    /// </summary>
    /// <example>
    ///     <UC:AnonymousTrimmedControl runat="server">
    ///         <ContentTemplate>
    ///             <!-- Any content over there that will not be rendered / visible for anonymous users -->
    ///         </ContentTemplate>
    ///     </UC:AnonymousTrimmedControl>
    /// </example>
    
    public class AnonymousTrimmedControl : ConditionallyVisibleControl
    {
        public override bool ShouldBeVisible
        {
            get
            {
                return (HttpContext.Current.Request.IsAuthenticated);
            }
        }
    }
    

    【讨论】:

    • 这是个好主意,尽管它会导致以复制母版页的形式进行额外的维护。我会赞成它,但它并没有真正回答我关于如何摆脱这些东西的问题......
    • 您可以让经过身份验证的母版页继承/使用您的公共母版页,以避免从头开始重新创建它。为了摆脱这些东西,它们中的大多数来自 SharePoint Web 控件,您可以在匿名母版页中将其关闭/删除。另一种解决方案是将它们包装在仅经过身份验证的模板控件中。我会在上面更新我的回复。
    • (继承我的意思是在私有属性上使用 MasterPageFile 属性,指向匿名属性,作为基础属性。)
    • 嗯..我得试试看。不幸的是,我们已经上线了该网站,管理层对此类重大变化非常敏感。我会看看我是否可以说服他们进行测试。我担心的是,大部分“混乱”是由页面上有一个 webpartmanager 引起的,我认为即使在我的匿名页面上我也必须有一个......
    猜你喜欢
    • 2011-09-10
    • 2012-07-15
    • 1970-01-01
    • 2014-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-17
    • 1970-01-01
    相关资源
    最近更新 更多