SuperSaiyan

I do all aspects related to high performance distributed web application system, such as RIA, Security, databse design and sql, javascript, c#, Asp.net, Software Factory. Among these, the database part is the key to performance.

导航

统计

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);
        }
    }

 

posted on   SuperSaiyan  阅读(200)  评论(0编辑  收藏  举报

编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· .NET周刊【3月第1期 2025-03-02】
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· [AI/GPT/综述] AI Agent的设计模式综述
点击右上角即可分享
微信分享提示