Skip to content

Instantly share code, notes, and snippets.

Avatar

Gregor Trcek GregorT

View GitHub Profile
@GregorT
GregorT / JavascriptOutputAttribute.cs
Last active Dec 28, 2017
Converting IActionResult view to javascript file with custom ActionFilterAttribute in Asp.Net Core 2x
View JavascriptOutputAttribute.cs
namespace yourApplicationNameSpace
{
public class JavascriptOutputAttribute : ActionFilterAttribute
{
private static readonly Regex OpenScriptTag = new Regex(@"^\s*<script[^>]*>", RegexOptions.Compiled);
private static readonly Regex CloseScriptTag = new Regex(@"</script>\s*$", RegexOptions.Compiled);
public override async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next)
{
var resp = context.HttpContext.Response;