You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am in the process of migrating our code slowly over to .net Standard 2.0 for our supplemental libraries, so that we can eventually migrate our huge application stack over to ASP.Net Core and .Net 5. We have been using HtmlTags for years, so I am trying to use the latest version of the library, however for some reason when we render a tag into HTML with ASP.net MVC 4.8, it does not render as HTML. The difference is ASP.net 4.8 is looking for IHtmlString on the class, to determine if it should be rendered as raw HTML, however it ends up not finding that. The HtmlTag class now has IHtmlContent as the interface which is compatible with ASP.net Core, but for some reason the version of ASP.NET MVC we are using is not supporting that.
What is the solution to get this working, so that ASP.net 4.8 will recognize IHtmlContent and render it correctly?
The text was updated successfully, but these errors were encountered:
Ok, so the problem is buried deep inside System.Web, as this is how HttpUtility.Encode() is implemented:
/// <summary>Converts an object's string representation into an HTML-encoded string, and returns the encoded string.</summary>/// <param name="value">An object.</param>/// <returns>An encoded string.</returns>publicstaticstringHtmlEncode(objectvalue){if(value==null)return(string)null;returnvalueisIHtmlStringhtmlString?htmlString.ToHtmlString():HttpUtility.HtmlEncode(Convert.ToString(value,(IFormatProvider)CultureInfo.CurrentCulture));}
Unfortunately there is nothing in there that knows about IHtmlContent. I don't see any updated packages for any of the related packages like Microsoft.AspNet.Mvc (5.2.7 is the latest), so there is no easy solution for this problem that I can think of. Best I can come up with at the moment is to derive my own view page for all our Razor views, and override the write function in there to understand IHtmlContent? It would work (and we already have our own custom base class to handle IoC), but it does mean if someone forgets to use it, stuff breaks.
I am in the process of migrating our code slowly over to .net Standard 2.0 for our supplemental libraries, so that we can eventually migrate our huge application stack over to ASP.Net Core and .Net 5. We have been using HtmlTags for years, so I am trying to use the latest version of the library, however for some reason when we render a tag into HTML with ASP.net MVC 4.8, it does not render as HTML. The difference is ASP.net 4.8 is looking for IHtmlString on the class, to determine if it should be rendered as raw HTML, however it ends up not finding that. The HtmlTag class now has IHtmlContent as the interface which is compatible with ASP.net Core, but for some reason the version of ASP.NET MVC we are using is not supporting that.
What is the solution to get this working, so that ASP.net 4.8 will recognize IHtmlContent and render it correctly?
The text was updated successfully, but these errors were encountered: