簡體   English   中英

SharePoint 2010 >> 編輯輸出 HTML >> 頁面或母版頁呈現覆蓋問題

[英]SharePoint 2010 >> Editing Output HTML >> Issues with page or master page render override

好的。 這是一個很大的。 我會嘗試解釋我的問題,但如果您需要更多信息,請告訴我。

我想更改 SharePoint 2010 生成的 HTML。 我將使用 HTML Agility Pack],它將在其他對象中獲取一串 HTML 並更改源。

有兩種方法可以更改 SP 中的完整源。

  1. 使用控件適配器或擴展控件,我可以訪問 Page、MasterPage 甚至 ContentPlaceHolder 呈現方法,獲取 HTML,更改它然后編寫它。
  2. 使用帶有過濾器的 HTTP 模塊並更改輸出流

不幸的是,這兩種方法都存在問題。

第 2 點,過濾器運行良好,但您必須禁用輸出緩存。 我不能這樣做。 我品牌的網站有大量的流量。 因此,在 SharePoint 2010 團隊修復/向我們提供解決方法之前,篩選器是沒有實際意義的。 我在旅行中的某個地方讀到了他們知道並將對此做些什么。

1 號效果很好。 我只是使用以下內容,我可以更改頁面的 HTML,但存在一個大問題。

HtmlDocument hd    = new HtmlDocument(); //Agility HTML Object.
StringBuilder sb   = new StringBuilder();
StringWriter sw    = new StringWriter(sb);
HtmlTextWriter htw = new HtmlTextWriter(sw);

//Render Object into HtmlTextWriter
base.Render(htw);

//String to hold the HTML from the StringBuilder of the HtmlTextWriter
string html = sb.ToString();

//Mess with the String here using the Agility HTML Pack

//Write the HTML to the writer
writer.Write(html);

//Done!

此代碼運行良好,但 SharePoint 2010 在頁面/母版頁的呈現覆蓋之后將數據附加到編寫器/或更改控件。

當我調試和演練並查看 html 字符串時,它看起來如下所示。

"<html ....  ....</html>"

這一點很重要,因為在第一個 HTML 標記之前沒有任何內容。 開頭“<”在位置 0。

但是當 HTML 在瀏覽器中結束時,我會看到以下內容。

DOMAIN\user<script type="text/javascript">
//<![CDATA[
var _spUserId=1;
//]]>
</script>
<html... 
....</html>

此外,功能區右上角的歡迎區域中也缺少用戶名,因為它現在將其放在開始標記之前。

如果我沒有在渲染中為 writer 對象分配任何內容,則瀏覽器中的頁面只會在 HTML 標記之前顯示所有內容。 有趣的是它不應該顯示任何東西!

如果我訪問其他頁面。 任何具有列表視圖的頁面。 所有項目都在標記之前呈現。 重要的是要注意它只是值,而不是 html。 列表項的 HTML 存在於它應該在列表視圖中的位置。

例如。 (頁面是“/_layouts/viewlsts.aspx”)

沒有渲染覆蓋。

<html...

...
//The Table where the data should be.
<tr>
    <td class="ms-gb"  colspan="5" style="white-space:nowrap;">
        <h3 class="ms-standardheader">
            &#160; Picture Libraries
        </h3>

    </td>
</tr>

<tr><td class="ms-vb2 ms-viewlsts-noitems" colspan="6">
    There are no picture libraries. To create one, click <b>Create</b> above.
</td></tr>

<tr>
    <td class="ms-gb"  colspan="5" style="white-space:nowrap;">
        <h3 class="ms-standardheader">

            &#160; Lists
        </h3>
    </td>
</tr>

<tr><td class="ms-vb2 ms-viewlsts-noitems" colspan="6">
    There are no lists. To create one, click <b>Create</b> above.
</td></tr>

<tr>

    <td class="ms-gb"  colspan="5" style="white-space:nowrap;">
        <h3 class="ms-standardheader">
            &#160; Discussion Boards
        </h3>
    </td>
</tr>

<tr class="ms-alternatingstrong">
    <td class="ms-vb-icon">

            <a id="viewlistDiscussionBoard" href="/Lists/Discussion%20Board/AllItems.aspx" >

            <img border="0" alt="Discussion Board" src="/_layouts/images/itdisc.png" width="16" height="16" /></a>
    </td>
    <td class="ms-vb2" >
            <a id="viewlistDiscussionBoard" href="/Lists/Discussion%20Board/AllItems.aspx">Discussion Board</a>&#160;
    </td>

    <td class="ms-vb2" width="40%" >
            &#160;
    </td>

    <td class="ms-vb2" width="3%" align="right">
    1
    </td>
    <td class="ms-vb2" width="25%" >
        <nobr>
        3 days ago
        </nobr>
    </td>
</tr>
...</html>

使用渲染覆蓋。

DOMAIN\user<script type="text/javascript">
//<![CDATA[
var _spUserId=1;
//]]>
</script>Document Libraries"viewlistDocumentLibrary""/AnalyticsReports/Forms/AllItems.aspx""Customized Reports""/_layouts/images/itdl.png""viewlistDocumentLibrary""/AnalyticsReports/Forms/AllItems.aspx"Customized ReportsThis Document library has the templates to create Web Analytics custom reports for this site collection04 days ago"viewlistDocumentLibrary""/Style%20Library/Forms/AllItems.aspx""Style Library""/_layouts/images/itdl.png""viewlistDocumentLibrary""/Style%20Library/Forms/AllItems.aspx"Style LibraryUse the style library to store style sheets, such as CSS or XSL files. The style sheets in this gallery can be used by this site or any of its subsites.04 days agoPicture LibrariesThere are no picture libraries. To create one, click <b>Create</b> above.ListsThere are no lists. To create one, click <b>Create</b> above.Discussion Boards"viewlistDiscussionBoard""/Lists/Discussion%20Board/AllItems.aspx""Discussion Board""/_layouts/images/itdisc.png""viewlistDiscussionBoard""/Lists/Discussion%20Board/AllItems.aspx"Discussion Board13 days agoSurveysThere are no surveys. To create one, click <b>Create</b> above.Blog0
<html...

//The Table where the data should be.
...
<tr>
    <td class="ms-gb"  colspan="5" style="white-space:nowrap;">
        <h3 class="ms-standardheader">

            &#160; 
        </h3>
    </td>
</tr>

<tr><td class="ms-vb2 ms-viewlsts-noitems" colspan="6">

</td></tr>

<tr>
    <td class="ms-gb"  colspan="5" style="white-space:nowrap;">
        <h3 class="ms-standardheader">

            &#160; 
        </h3>
    </td>
</tr>

<tr class="ms-alternatingstrong">
    <td class="ms-vb-icon">

            <a id= href= >
            <img border="0" alt= src= width="16" height="16" /></a>
    </td>

    <td class="ms-vb2" >
            <a id= href=></a>&#160;
    </td>

    <td class="ms-vb2" width="40%" >
            &#160;
    </td>
    <td class="ms-vb2" width="3%" align="right">

    </td>
    <td class="ms-vb2" width="25%" >

        <nobr>

        </nobr>
    </td>
</tr>
... </html>

我的猜測是它與資源文件有關..

無論如何,很明顯在 Page 或 MasterPage 呈現方法之后對對象進行了某種操作。 我就是找不到。

我的 HTTP 模塊過濾器流在適當的位置有 HTML .. 所以在頁面呈現和將 HTML 發送到瀏覽器之間的某個地方發生了一些事情。

這里有幾個其他人報告了同樣的問題,但沒有任何有用的回應。

  1. 鏈接 1
  2. 鏈接 2

我將不勝感激任何對此的見解! 謝謝!

該問題是由頁面中的某些內容在渲染期間干擾輸出緩存引起的,更具體地說是 PostCacheSubstitutionTextHelper 類的行為。 可能您調用上面的 Render 會觸發此操作。

Welcome.asxc 控件的行為大致如下(偽序列圖):

頁面渲染 > Welcome.ascx 渲染 > PersonalActions 渲染 > PostCacheSubstitutionText.Render > PostCacheSubstitutionTextHelper.RenderAndRegisterSubstitutionCallbackHandler(新實例)PostCacheSubstitutionText.Render(在委托中調用,現在寫入 HtmlTextWriter)> PostCacheSubstitutionTextHelper。 RenderAndRegisterSubstitutionCallbackHandler HttpContext.Response.WriteSubstitution(stuffFromNewInstanceOfPostCacheSubstitutionText)

有了 sharepoint freakshow 和解決方法就足夠了:-)

嘗試將其添加到配置單元中的welcome.ascx:

// in bottom of directives in /CONTROLTEMPLATES/Welcome.ascx
<%@ OutputCache Duration="1" VaryByParam="none" %>

請注意,Duration 設置為 1,因為用戶控件不允許為 0。 這在理論上存在失敗的可能性,但在我們的場景中它有效。

我遇到了同樣的問題,我能夠通過從母版頁中刪除這一行來解決這個問題。

<wssuc:Welcome id="IdWelcome" runat="server">
</wssuc:Welcome>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM