Skip to content

Instantly share code, notes, and snippets.

@chrsin
Created April 24, 2019 08:35
Show Gist options
  • Save chrsin/fac39ed263eb816ed66d59d8c9816f33 to your computer and use it in GitHub Desktop.
Save chrsin/fac39ed263eb816ed66d59d8c9816f33 to your computer and use it in GitHub Desktop.
using System.Diagnostics.CodeAnalysis;
using System.Web;
using System.Web.Http.Controllers;
using System.Web.Http.Filters;
using ActionFilterAttribute = System.Web.Http.Filters.ActionFilterAttribute;
namespace MyWebsite
{
[ExcludeFromCodeCoverage]
public class RemoveCookiesFilterAttribute : ActionFilterAttribute
{
public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
{
IHttpController controller = actionExecutedContext.ActionContext.ControllerContext.Controller;
if (controller != null)
{
string ns = controller.GetType().Namespace;
if(ns != null && ns.StartsWith("MyWebsite"))
HttpContext.Current.Response.Cookies.Clear();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment