0

Hello I am trying using the OutputCache inheriting a base controller. But it is not working, my codes:

BaseController

 public abstract partial class BasicControllerController : Controller
{

    protected override void Initialize(System.Web.Routing.RequestContext requestContext)
    {
        if (requestContext == null)
        {
            throw new ArgumentNullException("filterContext");
        }
        base.Initialize(requestContext);
    }
}

Controller

 [OutputCache(Duration=60)]
public class SamplesController : BasicControllerController
{
    public ActionResult AgendamentoEmail()
    {
        return View();
    }
}

View

@System.DateTime.Now

But just not working. It only works if I did not inherit, or I remove the code below the base controller

public abstract partial class BasicControllerController : Controller
{
    //protected override void Initialize(System.Web.Routing.RequestContext requestContext)
    //{
    //    if (requestContext == null)
    //    {
    //        throw new ArgumentNullException("filterContext");
    //    }
    //    base.Initialize(requestContext);
    //}

}

I think I have to do some implementation in protected override void Initialize.

Detail: I need this method, as there is variables that use other controllers

José Luiz
  • 334
  • 1
  • 5
  • 18

1 Answers1

0

I have dealt with this before and found that some pre existing Attributes cannot be inherited because they were designed that way in their declaration.

The only way that I found is to create a new attribute that extends the one you want to use but marked as Inherited, liked this:

[AttributeUsage (Inherited = True)]
public class InheritedOutputCacheAttribute : OutputCacheAttribute
{
...
}
Nick
  • 2,877
  • 2
  • 33
  • 62
  • Helo.. tanks... I tried but it did not work .. do you have any more detailed example?`[AttributeUsage(AttributeTargets.All,Inherited=false)] public class DonutCacheAttribute : OutputCacheAttribute { public DonutCacheAttribute() { // get cache duration from web.config Duration = Settings.DonutCachingDuration; } }` – José Luiz Jun 19 '15 at 18:24
  • Inherited should be true, not false... did you try that? – Nick Jun 24 '15 at 13:22