FileUltimate v9.0.3
Version 9.0.3 - August 2, 2024
-
Improved: Added EscapeClosingScriptTags method to RazorPageExtensions, WebViewPageExtensions and WebPageExtensions
which escapes closing script tags, i.e. replaces</script>
with<\/script>
.When you render a component inside a
<script>
tag, for example when you set a javascript variable to
the result of inline @renderhead or @RenderBody calls, the result may contain closing</script>
tags
and browser treats these tags as an immediate stop even if they are enclosed in a javascript string literal:<script> //this will fail in browser because there are closing `</script>` tags in the rendered result. var html = `@this.RenderBody(component)`; </script>
So to prevent the issue, escape closing script tags when you are inside
<script>
tag, with this method:<script> var html = `@this.RenderBody(component).EscapeClosingScriptTags()`; </script>
Details: The browser finds the </script> piece in the string and thinks that it is the closing tag
of the first script element. It treats the rest of the script and the real </script> closing tag as regular text
and displays it in the page (except for the </script> tag).
Included example projects:
- ASP.NET Core (C#) - Visual Studio 2019+
- ASP.NET Core on .NET Framework (C#)- Visual Studio 2017+
- ASP.NET MVC (C#) - Visual Studio 2015+
- ASP.NET MVC (VB) - Visual Studio 2015+
- ASP.NET WebForms (C#) - Visual Studio 2015+
- ASP.NET WebForms (VB) - Visual Studio 2015+