/*******************************HeaderFiterAttribute.cs**************************************/
using Microsoft.AspNetCore.Mvc.Filters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace PocoDemo
{
public class HeaderFiterAttribute:ActionFilterAttribute
{
public string Name { get; set; }
public string Value { get; set; }
public override void OnActionExecuted(ActionExecutedContext context)
{
if (!string.IsNullOrEmpty(Name) && !string.IsNullOrEmpty(Value))
{
context.HttpContext.Response.Headers.Add(Name, Value);
}
base.OnActionExecuted(context);
}
}
}
/***************************TestController.cs**************************************************/
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace PocoDemo
{
public class TestController:Controller
{
[HeaderFiter(Name ="Test",Value ="Index")]
public IActionResult Index()
{
return Content("just verify action filter");
}
}
}