Initial commit: JDE Scoping Tool migration project
Set up repository with legacy .NET Framework 4.8 source (OLD/), new .NET 10 Blazor solution (NEW/), OpenSpec specifications, documentation, and project configuration.
This commit is contained in:
Executable
+66
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace WebInterface.Helpers
|
||||
{
|
||||
/// <summary>
|
||||
/// Custom JSON action result using JSON.NET library
|
||||
/// </summary>
|
||||
public class JsonNetResult : JsonResult
|
||||
{
|
||||
/// <summary>
|
||||
/// Serialization settings
|
||||
/// </summary>
|
||||
public JsonSerializerSettings Settings { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
public JsonNetResult()
|
||||
{
|
||||
Settings = new JsonSerializerSettings
|
||||
{
|
||||
ReferenceLoopHandling = ReferenceLoopHandling.Error
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Generates the resulting JSON output
|
||||
/// </summary>
|
||||
/// <param name="context">Controller context for outputting</param>
|
||||
public override void ExecuteResult(ControllerContext context)
|
||||
{
|
||||
//Verify context is valid before continuing
|
||||
if (context == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
//Verify HTTP method is valid before continuing
|
||||
if (JsonRequestBehavior == JsonRequestBehavior.DenyGet && string.Equals(context.HttpContext.Request.HttpMethod, "GET", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
throw new InvalidOperationException("JSON GET is not allowed");
|
||||
}
|
||||
|
||||
//Write response
|
||||
HttpResponseBase response = context.HttpContext.Response;
|
||||
response.ContentType = string.IsNullOrEmpty(ContentType) ? "application/json" : ContentType;
|
||||
|
||||
if (ContentEncoding != null)
|
||||
response.ContentEncoding = ContentEncoding;
|
||||
if (Data == null)
|
||||
return;
|
||||
|
||||
var scriptSerializer = JsonSerializer.Create(Settings);
|
||||
|
||||
using (var sw = new StringWriter())
|
||||
{
|
||||
scriptSerializer.Serialize(sw, Data);
|
||||
response.Write(sw.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user