asp.net 的一个新bug. 当你的程序出问题时, 不仅仅要检查自己的代码和逻辑, 还要检查微软的代码, 累吗?

当你的程序出问题时, 不仅仅要检查自己的代码和逻辑, 还要检查微软的代码, 累吗?  原文在: http://forums.asp.net/t/1192141.aspx , 转给这里.

if you cache two usercontrols in a page, and both of which contains either a menu or  treeview(or any control that injects embeded css style into parent page), then the first time you get the response right, but on second  request or any later request where the cached content is used, the outout will not be correct. inspecting the html source, I found some inline style definition is missing for the later response. It seems this is a bug in asp.net: BasePartialCachingControl.PreRenderRecursiveInternal(), where only the last cached style output is used, and any previous style string set by other cached usercontrols positioned earlier in the page is overwritten.

Besides the senerio of two side by side usercontrols being cached, there is another senerio, suppose one usercontrol uses embedded style(both menu and treeview use these, and many other ajax controls also use this technique to inject style definition into the html head element), and it contains a child usercontrol who is also set to cached, and also uses embedded style, the two controls expiration event will ussually not coincident, and now suppose that the parent one is being regenerated while the child one has still a valid cached version, in this case, since the child one's css settings will go through the path of page.header.StyleSheet.CSSStyleString (in BasePartialCachingControl.PreRenderRecursiveInternal), so it will not be merged with the parent control's css setting, which results an incorrect css setting string being stored into cache, so any subsequence output of the parent usercontrol from cache will be incorrect. 

I once wondered if this had been fixed in latest service pack, so downloaded .net framework 2.0 service pack 1, unfortunately, it was not.

 hope someone can verify the above, and if verified a bug, hope Microsoft can fix this bug.

a suggested fix for it:

in basepartial, add a childrenCssRawstring property
in basepartial.GetCssStyleRenderString(), append childrenCssRawstring to the final output

change RegisterCssStyleString to:
internal void StyleSheetInternal.RegisterCssStyleString(string outputString)
{
    ((StyleSheetInternal) this.StyleSheet).CSSStyleString +="/r/n"+ outputString;

    Page page = this._owner.Page;
    if (page.PartialCachingControlStack != null)
    {
        foreach (BasePartialCachingControl control in page.PartialCachingControlStack)
        {
            control.appendcssRawString(outputString);
        }
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值