Skip to content

Commit

Permalink
adding . applying filter
Browse files Browse the repository at this point in the history
  • Loading branch information
inada authored and mikecp committed Oct 24, 2021
1 parent e5549b7 commit 2d34624
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.PublishedCache;
using Umbraco.Cms.Web.BackOffice.Controllers;
using Umbraco.Cms.Web.Common.Attributes;
using Umbraco.Cms.Web.Common.Filters;
using Umbraco.Extensions;
using Constants = Umbraco.Cms.Core.Constants;

Expand Down Expand Up @@ -33,6 +34,8 @@ public TagsDataController(ITagQuery tagQuery)
/// <param name="culture"></param>
/// <param name="query"></param>
/// <returns></returns>
///
[AllowHttpJsonConfigration]
public IEnumerable<TagModel> GetTags(string tagGroup, string culture, string query = null)
{
if (culture == string.Empty) culture = null;
Expand Down
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>();
}
}
}
}
}

0 comments on commit 2d34624

Please sign in to comment.