【问题标题】:Change default idseparator in .Net 3.5?更改 .Net 3.5 中的默认 idseparator?
【发布时间】:2014-12-30 10:26:50
【问题描述】:

好的, 场景如下:

我们将一个遗留的 Web 项目从 .Net 1.1 移植到 .Net 3.5,大多数事情都按照预期的方式工作。

但我们遇到了一个奇怪的情况, 即使在 .Net 2.0 中用于在 webcontrols 中呈现名称的 idseparator 从“:”更改为 .Net 2.0 中的“$”,我们的本地开发机器仍然使用“:”作为名称的 idseparator 呈现 Asp.Net 控件。

但是,当我们将 Web 项目部署到其中一台测试服务器时,那些相同的 asp.net 控件正在使用“$”作为名称的 idseparator 呈现。

所以,

问题 1: 为什么它只在我们的测试服务器上而不是在我们的本地机器上表现这种方式?

问题 2: 即使我们设法“修复”我们的本地开发机器以呈现正确的默认字符分隔符(“$”),它也会破坏一些遗留的 js 代码,它假定 asp.net 控件使用“:”分隔符呈现名称。 我们能否将测试服务器中的默认字符分隔符改回冒号(“:”)?

【问题讨论】:

    标签: asp.net .net web-controls


    【解决方案1】:

    对如何使用 .NET Reflector 生成 UniqueID 的快速回顾表明,您可以通过在 Web.Config 中使用 <xhtmlConformance mode="Legacy" /> 来获取“:”而不是“$”。

    但它可能会引入其他问题。

    详情:

    有一个受保护的属性 Control.IdSeparator 在生成 UniqueId 期间内部用于获取分隔符:

    protected char IdSeparator
    {
      [TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
      get
      {
        if (this.Page != null)
        {
          return this.Page.IdSeparator;
        }
        return this.IdSeparatorFromConfig;
      }
    }
    

    IdSeparatorFromConfig 在哪里

    internal char IdSeparatorFromConfig
    {
      get
      {
        if (!this.EnableLegacyRendering)
        {
          return '$';
        }
        return ':';
      }
    }
    

    EnableLegacyFromConfig

    internal bool EnableLegacyRendering
    {
        get
        {
            System.Web.UI.Page page = this.Page;
            if (page != null)
            {
                return (page.XhtmlConformanceMode == XhtmlConformanceMode.Legacy);
            }
            return ((!this.DesignMode && (this.Adapter == null)) && (this.GetXhtmlConformanceSection().Mode == XhtmlConformanceMode.Legacy));
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-09-07
      • 2021-07-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-25
      • 2022-01-09
      相关资源
      最近更新 更多