I am having a tuff time trying to get an instace of a HttpRequestMessage so I can pass it to the method GetCacheOutputProvider
below from an ActionFilter and/or normal ASP.NET MVC Controller. I know I can from the Web API, but what about these instances.
public class CacheResetFilter : ActionFilterAttribute
{
public override void OnActionExecuted(ActionExecutedContext filterContext)
{
var cache = GlobalConfiguration.Configuration.CacheOutputConfiguration().GetCacheOutputProvider(HTTPREQUESTMESSAGE);
cache.Contains("eventid=" + eventId);
base.OnActionExecuted(filterContext);
}
1.In a MVC Controller you can do like:
public class HomeController : Controller
{
public ActionResult Test()
{
HttpRequestMessage httpRequestMessage =
HttpContext.Items["MS_HttpRequestMessage"] as HttpRequestMessage;
return View();
}
}
2.In action filter you can do like :
public class HttpRequestMessageAttribute : System.Web.Mvc.ActionFilterAttribute
{
public override void OnActionExecuted(System.Web.Mvc.ActionExecutedContext filterContext)
{
HttpRequestMessage httpRequestMessage =
filterContext.HttpContext.Items["MS_HttpRequestMessage"] as HttpRequestMessage;
//var cache = GlobalConfiguration.Configuration.CacheOutputConfiguration().GetCacheOutputProvider(httpRequestMessage);
//cache.Contains("eventid=" + eventId);
base.OnActionExecuted(filterContext);
}
}
OR
public class HttpRequestMessageAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
HttpRequestMessage httpRequestMessage =
filterContext.HttpContext.Items["MS_HttpRequestMessage"] as HttpRequestMessage;
base.OnActionExecuting(filterContext);
}
}
Hopefully it's help for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With