forked from umbraco/Umbraco-CMS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
46 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/Umbraco.Web.Common/Filters/AllowHttpJsonConfigrationAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System; | ||
using System.Buffers; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.Filters; | ||
using Microsoft.Extensions.Options; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Converters; | ||
using Newtonsoft.Json.Serialization; | ||
using Umbraco.Cms.Web.Common.Formatters; | ||
|
||
namespace Umbraco.Cms.Web.Common.Filters | ||
{ | ||
public class AllowHttpJsonConfigrationAttribute : TypeFilterAttribute | ||
{ | ||
/// <summary> | ||
/// This filter overwrites AngularJsonOnlyConfigurationAttribute and get the api back to its defualt behavior | ||
/// </summary> | ||
public AllowHttpJsonConfigrationAttribute() : base(typeof(AllowJsonXHRConfigrationFilter)) | ||
{ | ||
Order = 2; // this value must be more than the AngularJsonOnlyConfigurationAttribute on order to overwrtie it | ||
} | ||
|
||
private class AllowJsonXHRConfigrationFilter : IResultFilter | ||
{ | ||
public void OnResultExecuted(ResultExecutedContext context) | ||
{ | ||
} | ||
|
||
public void OnResultExecuting(ResultExecutingContext context) | ||
{ | ||
if (context.Result is ObjectResult objectResult) | ||
{ | ||
objectResult.Formatters.RemoveType<AngularJsonMediaTypeFormatter>(); | ||
} | ||
} | ||
} | ||
} | ||
} |