Skip to content

Proposal to add HtmlEncode to HttpServerUtility #683

@ptuukkan

Description

@ptuukkan

Summary

Add HtmlEncode overloads to HttpServerUtility (and its Base/Wrapper mirrors) so code migrating from System.Web that calls Server.HtmlEncode(...) compiles and runs against the adapters without changes.
I was thinking of using WebUtility.HtmlEncode in the methods but do you think it would be better to use HttpUtility.HtmlEncode instead?

Motivation and goals

We are migrating an ASP.NET application to CoreWebForms. We use Telerik UI and some of their components such as RadAjaxLoadingPanel depends on using System.Web.HttpServerUtility.HtmlEncode(System.String). Adding HtmlEncode to HttpServerUtility would help us greatly with the migration.

Example:

System.MissingMethodException: Method not found: 'System.String System.Web.HttpServerUtility.HtmlEncode(System.String)'.
    at Telerik.Web.SkinRegistrar.RegisterStyleSheetReference(ISkinnableControl control, StyleSheetReference reference, StringBuilder cssRegs, Type controlToRegisterType)

In scope

  • string? HtmlEncode(string? value) on HttpServerUtility, returning the encoded string (annotated [NotNullIfNotNull("value")]).
  • void HtmlEncode(string? value, TextWriter output) on HttpServerUtility, writing directly to a TextWriter.
  • Matching virtual declarations on HttpServerUtilityBase and pass-through overrides on HttpServerUtilityWrapper.
  • Backing implementation delegated to System.Net.WebUtility.HtmlEncode.

Out of scope

I was thinking not to include HtmlDecode overloads here but if you think it should be done simultaneously we can do it.

Risks / unknowns

  • WebUtility or HttpUtility
  • Should we use the signature of the old method string HtmlEncode(string s) or match the signature to WebUtilitys HtmlEncode string? HtmlEncode(string? value)
  • Unsure about other unknowns or risks. Old HttpServerUtility had these methods.

Examples

  • HttpContext.Current.Server.HtmlEncode(value)
  • System.Web.HttpServerUtility.HtmlEncode(value)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs: Triage 🔍Label added to new issues which need Triage

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions