【问题标题】:Default RadGrid html encoding默认 RadGrid html 编码
【发布时间】:2020-10-12 10:13:24
【问题描述】:

ASP.NET webforms 应用程序使用 Telerik 组件(网格、标签、下拉菜单)来显示数据。

要求是在 UI 上呈现数据时html encode 数据。实现了白名单以允许几个安全的 html 标签,如<table><b><br>。自定义的http编码器配置在web.config

  • web.config
<httpRuntime encoderType="WebApp.Common.Security.AppHttpEncoder, WebApp.Common" />

Telerik 网格允许配置 html 编码,例如在 c# 中,但这里的白名单是必需的。

protected void RadItemsGrid_ColumnCreated(object sender, GridColumnCreatedEventArgs e)
{
    var boundColumn = e.Column as GridBoundColumn;
    if (boundColumn != null)
    {
        boundColumn.HtmlEncode = true;
    }
}

问题是如何将 .NET 默认的 html 编码器设置为 Telerik 网格?有没有办法在代码中设置?类似的东西

RadGrid.Encoder = xxx

【问题讨论】:

    标签: asp.net security webforms telerik html-encode


    【解决方案1】:

    这些动作到底都做了

    • web.config - 删除了自定义 httpEncoder,因此到处都只使用默认的 .NET 编码器。
    • 自定义 AppHttpEncoder 在需要时明确使用

    这有助于提高性能,默认情况下到处都有 html 编码,并且在需要的地方调整了代码并使用了自定义白名单 http 编码器。

    【讨论】:

      猜你喜欢
      • 2010-10-15
      • 1970-01-01
      • 1970-01-01
      • 2011-05-16
      • 2015-07-08
      • 1970-01-01
      • 2012-01-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多