SharePoint 2010>>编辑输出HTML>>页面或主页面渲染覆盖问题 [英] SharePoint 2010 >> Editing Output HTML >> Issues with page or master page render override

查看:81
本文介绍了SharePoint 2010>>编辑输出HTML>>页面或主页面渲染覆盖问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

确定。这是一个很大的问题。我会尝试解释我的问题,但请告知我是否需要更多信息。



我想更改SharePoint 2010生成的HTML。
我将要使用HTML敏捷包],它会在其他对象中使用一串HTML并改变源代码。



有两种方法改变SP中的完整源代码。


  1. 使用控制适配器或扩展控件我可以访问Page,MasterPage或者ContentPlaceHolder渲染方法,抓取HTML,修改它,然后编写它。

  2. 使用带有过滤器的HTTP模块并更改输出流

不幸的是,这两种方法都存在问题。

数字2,过滤器工作正常,但必须禁用输出缓存。
我不能这样做。我品牌的网站有大量的流量。
因此,在SharePoint 2010团队修复/向我们提供解决方法之前,过滤器一直未启用。我读了一些他们知道的旅行地点,并且会为此做点什么。



1号很棒。我简单地使用以下内容,我可以改变页面的HTML,但有一个大问题。

  HtmlDocument hd = new HtmlDocument (); // Agility HTML对象。 
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
HtmlTextWriter htw = new HtmlTextWriter(sw);

//将对象渲染为HtmlTextWriter
base.Render(htw);

//用于保存HtmlTextWriter的StringBuilder中的HTML的字符串
string html = sb.ToString();

//使用Agility HTML Pack将字符串混淆

//将HTML写入作者
writer.Write(html);

//完成!

这段代码很好用,但SharePoint 2010将数据附加到writer /或者在渲染后更改控件覆盖页面/母版页。



当我调试并浏览html字符串时,它看起来像下面那样。

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

这一点很重要,因为第一个HTML标签之前没有任何东西。开幕式<



但是,当HTML在浏览器中结束时,我会看到以下内容。

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

另外,功能区右上方的欢迎区域中缺少用户名,因为它现在正在放置如果我不在渲染覆盖中指定编写器对象的任何东西,浏览器中的页面只显示HTML标记之前的所有内容。有趣的是它不应该显示任何东西!



如果我访问其他页面。任何有列表视图的页面。所有的项目都在标签之前呈现。重要的是要注意,它只是价值观,而不是html。列表项的HTML存在于列表视图中。



例如。 (Page is/_layouts/viewlsts.aspx)



没有渲染覆盖。

 < html ... 

...
//数据应该在的表格。
< tr>
< td class =ms-gbcolspan =5style =white-space:nowrap;>
< h3 class =ms-standardheader>
&#160;图片库
< / h3>

< / td>
< / tr>

< tr>< td class =ms-vb2 ms -viewlsts-noitemscolspan =6>
没有图片库。要创建一个,请点击< b>创建< / b>以上。
< / td>< / tr>

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

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

< tr>< td class =ms-vb2 ms -viewlsts-noitemscolspan =6>
没有列表。要创建一个,请点击< b>创建< / b>以上。
< / td>< / tr>

< tr>

< td class =ms-gbcolspan =5style =white-space:nowrap;>
< h3 class =ms-standardheader>
&#160;讨论板
< / h3>
< / td>
< / tr>

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

< a id =viewlistDiscussionBoardhref =/ Lists / Discussion%20Board / AllItems.aspx>

< img border =0alt =讨论区src =/ _ layouts / images / itdisc.pngwidth =16height =16/><一个>
< / td>
< td class =ms-vb2>
< a id =viewlistDiscussionBoardhref =/ Lists / Discussion%20Board / AllItems.aspx>讨论区< / a>&#160;
< / td>

< td class =ms-vb2width =40%>
&#160;
< / td>

< td class =ms-vb2width =3%align =right>
1
< / td>
< td class =ms-vb2width =25%>
< nobr>
3天前
< / nobr>
< / td>
< / tr>
...< / html>

使用渲染覆盖。

  DOMAIN \ user< script type =text / javascript> 
//<![CDATA [
var _spUserId = 1;
//]]>
< / script>文档库viewlistDocumentLibrary/ AnalyticsReports / Forms / AllItems.aspxCustomized Reports/ _ layouts / images / itdl.pngviewlistDocumentLibrary/ AnalyticsReports / Forms / AllItems.aspx 自定义报告此文档库包含用于为此网站集创建Web Analytics自定义报告的模板4天前viewlistDocumentLibrary/ Style%20Library / Forms / AllItems.aspxStyle Library/ _ layouts / images / itdl.png viewlistDocumentLibrary/ Style%20Library / Forms / AllItems.aspx样式库使用样式库来存储样式表,如CSS或XSL文件。此图库中的样式表可供本网站或其任何子网站使用.4天前图片库没有图片库。要创建一个,请点击< b>创建< / b>列表没有列表。要创建一个,请点击< b>创建< / b>讨论区论坛讨论区讨论区讨论区13讨论区几天前苏尔维斯没有调查。要创建一个,请点击< b>创建< / b> aboveBlog0
< html ...

//数据应该在的表格。
...
< tr>
< td class =ms-gbcolspan =5style =white-space:nowrap;>
< h3 class =ms-standardheader>

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

< tr>< td class =ms-vb2 ms -viewlsts-noitemscolspan =6>

< / td>< / tr>

< tr>
< td class =ms-gbcolspan =5style =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 =0alt = src = width =16height =16/>< / a>
< / td>

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

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

< / td>
< td class =ms-vb2width =25%>

< nobr>

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

我的猜测是它与资源文件有关。



无论是哪种情况,显然在Page或MasterPage呈现方法之后都会对对象进行某种操作。我只是找不到它。



我的HTTP模块过滤器流在正确的地方有HTML。
因此,页面渲染和发送HTML到浏览器有一些事情正在发生。



以下是一些其他人在报告相同问题时没有任何有用的回复。


  1. 链接1
  2. 链接2

我很感谢这方面的任何见解!感谢!

解决方案

这个问题是由页面中的某些内容在渲染过程中干扰outputcache造成的,更具体地说, PostCacheSubstitutionTextHelper类。



welcome.asxc控件的行为大致如下(伪序列图):
$ b $ PostCacheSubstitutionText.Render> PostCacheSubstitutionTextHelper.RenderAndRegisterSubstitutionCallbackHandler $ b $(PostCacheSubstitutionText.Render的新实例)(在委托中调用,现在写入HtmlTextWriter)> PostCacheSubstitutionTextHelper。 RenderAndRegisterSubstitutionCallbackHandler HttpContext.Response.WriteSubstitution(stuffFromNewInstanceOfPostCacheSubstitutionText)


足够的分享点freakshow和解决方法: - )

$ / b
$ b

  //在/ CONTROLTEMPLATES / Welcome中的指令底部添加此代码.ascx 
<%@ OutputCache Duration =1VaryByParam =none%>

请注意,持续时间设置为1,因为用户控件不允许使用0。这给失败留下了理论上的可能性,但在我们的情况下它起作用了。

Ok. This is a big one. I'll try and explain my issue but let me know if you need more info.

I would like to alter the HTML that SharePoint 2010 generates. I'm going to use the HTML Agility Pack] which will take a string of HTML among other objects and alter the source.

There are 2 ways of altering the full source in SP.

  1. Using Control Adapters, or Extending Controls I can access the Page, MasterPage or even ContentPlaceHolder render methods, grab the HTML, Alter it and then write it.
  2. Use a HTTP Module with a filter and alter the output stream

Unfortunately there are issues with both of these methods.

Number 2, the filter works good but you have to disable the Output Cache. I can't do this. The sites I brand have massive amounts of traffic. So filters are moot until the SharePoint 2010 team fixes / presents us with a workaround. I read somewhere in my travels they are aware and will be doing something about it.

Number 1 works great. I simply use the following and I can alter the HTML of the page but there is one big problem.

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!

This code works great, but SharePoint 2010 is appending data to the writer / or altering controls after the render override for the Page / MasterPage.

When i debug and walk-through and look at the html string it look like the following.

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

This is important to note because there is nothing before the first HTML tag. The Opening "<" is in position 0.

But when the HTML ends up in the browser I see the following.

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

Also the user name is missing from the welcome area in the top right of the ribbon because it's now putting it up before the opening tag.

If I don't assign the writer object anything in the render override the page in the browser just shows everything before the HTML tag. The funny thing is it shouldn't show anything!

If I visit other pages. ANY page that has a list view. All of the items are rendered before tag. It's important to note that it's just the Values, not the html. The HTML for the list items exists where it should down in the list view.

For Example. (Page is "/_layouts/viewlsts.aspx" )

Without the render override.

<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>

With the render override.

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>

My guess is it has something to do with resource files..

Whatever the case it's obvious that there is some sort of manipulation of the objects after the Page or MasterPage render methods. I just can't find it.

My HTTP Module filter stream has the HTML in the proper place.. So somewhere between the Page render and sending the HTML to the browser there is something going on.

Here are a couple of other people reporting the same issue without any useful responses.

  1. Link 1
  2. Link 2

I would appreciate any insight on this! THANKS!

解决方案

The problem is caused by something in the page interfering with the outputcache during render, and more specifically the behaviour of the PostCacheSubstitutionTextHelper class. Probably your call to Render above triggers this.

The welcome.asxc control behaves approximately like this (pseudo sequence diagram):

Page Render > Welcome.ascx Render > PersonalActions Render > PostCacheSubstitutionText.Render > PostCacheSubstitutionTextHelper.RenderAndRegisterSubstitutionCallbackHandler (new instance of)PostCacheSubstitutionText.Render(called in delegate and now writes to HtmlTextWriter) > PostCacheSubstitutionTextHelper. RenderAndRegisterSubstitutionCallbackHandler HttpContext.Response.WriteSubstitution(stuffFromNewInstanceOfPostCacheSubstitutionText)

So enough with the sharepoint freakshow and over to the workaround:-)

Try adding this to your welcome.ascx in the hive:

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

Notice that the Duration is set to 1 since 0 is not allowed for user controls. this leaves a theoretical possiblity for failure, but in our scenario it worked.

这篇关于SharePoint 2010&gt;&gt;编辑输出HTML&gt;&gt;页面或主页面渲染覆盖问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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