title: ASP.NET MVC4 - OutputCache exception
body: <p>I'm able to appropriately utilize the ASP.NET <strong><em>MVC4 OutputCache</em></strong> with the following code as an attribute on my Controller's Index():</p>
  
  <pre><code>[OutputCache(Duration = 600, VaryByParam = "none")]
  </code></pre>
  
  <p>However,</p>
  
  <p>To manage differing caching scenario's, per <strong><em><a href="http://msdn.microsoft.com/en-us/library/ms178606.aspx" rel="nofollow">the MSDN documentation</a></em></strong> we can cache (for example) our controllers Index() method using <strong><em>OutputCache</em></strong>. Following the documentation we end up with the following code:</p>
  
  <p><em><strong>in our Controller</em></strong></p>
  
  <pre><code>    //[OutputCache(Duration = 600, VaryByParam = "none")] //works without any modification to the Web.config
      [OutputCache(CacheProfile = "Cache1Hour", VaryByParam = "none")]
      public ActionResult Index()
      {
          return View();
      }
  </code></pre>
  
  <p>and <strong><em>in our Web.config</em></strong></p>
  
  <pre><code>  &lt;system.web&gt;
      &lt;caching&gt;
        &lt;outputCacheSettings&gt;
            &lt;outputCacheProfiles&gt;
                &lt;add name="Cache1Hour" duration="3600"/&gt;
            &lt;/outputCacheProfiles&gt;
        &lt;/outputCacheSettings&gt;
      &lt;/caching&gt;
              ...
              ...
              ...
    &lt;/system.web&gt;
  </code></pre>
  
  <p><strong>Question/Problem:</strong> <em><strong>evidently I'm missing something as I continually throw the following exception:</em></strong></p>
  
  <p>Exception Details: System.Web.HttpException: The 'Cache1Hour' cache profile is not defined.  Please define it in the configuration file.</p>
  
  <p><em><strong>full exception:</em></strong></p>
  
  <pre><code>Server Error in '/' Application.
  The 'Cache1Hour' cache profile is not defined.  Please define it in the configuration file.
  Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
  
  Exception Details: System.Web.HttpException: The 'Cache1Hour' cache profile is not defined.  Please define it in the configuration file.
  
  Source Error:
  
  An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
  
  Stack Trace:
  
  
  [HttpException (0x80004005): The 'Cache1Hour' cache profile is not defined.  Please define it in the configuration file.]
     System.Web.UI.Page.InitOutputCache(OutputCacheParameters cacheSettings) +3136900
     System.Web.Mvc.OutputCachedPage.FrameworkInitialize() +47
     System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +48
     System.Web.UI.Page.ProcessRequest() +72
     System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +21
     System.Web.UI.Page.ProcessRequest(HttpContext context) +58
     System.Web.Mvc.OutputCacheAttribute.OnResultExecuting(ResultExecutingContext filterContext) +184
     System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +72
     System.Web.Mvc.&lt;&gt;c__DisplayClass1c.&lt;InvokeActionResultWithFilters&gt;b__19() +72
     System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +388
     System.Web.Mvc.&lt;&gt;c__DisplayClass1c.&lt;InvokeActionResultWithFilters&gt;b__19() +72
     System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +303
     System.Web.Mvc.Async.&lt;&gt;c__DisplayClass2a.&lt;BeginInvokeAction&gt;b__20() +155
     System.Web.Mvc.Async.&lt;&gt;c__DisplayClass25.&lt;BeginInvokeAction&gt;b__22(IAsyncResult asyncResult) +184
     System.Web.Mvc.Async.WrappedAsyncResult`1.End() +136
     System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56
     System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +40
     System.Web.Mvc.&lt;&gt;c__DisplayClass1d.&lt;BeginExecuteCore&gt;b__18(IAsyncResult asyncResult) +40
     System.Web.Mvc.Async.&lt;&gt;c__DisplayClass4.&lt;MakeVoidDelegate&gt;b__3(IAsyncResult ar) +47
     System.Web.Mvc.Async.WrappedAsyncResult`1.End() +151
     System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59
     System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
     System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +44
     System.Web.Mvc.Async.&lt;&gt;c__DisplayClass4.&lt;MakeVoidDelegate&gt;b__3(IAsyncResult ar) +47
     System.Web.Mvc.Async.WrappedAsyncResult`1.End() +151
     System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59
     System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
     System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +39
     System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +39
     System.Web.Mvc.&lt;&gt;c__DisplayClass8.&lt;BeginProcessRequest&gt;b__3(IAsyncResult asyncResult) +45
     System.Web.Mvc.Async.&lt;&gt;c__DisplayClass4.&lt;MakeVoidDelegate&gt;b__3(IAsyncResult ar) +47
     System.Web.Mvc.Async.WrappedAsyncResult`1.End() +151
     System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59
     System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
     System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +40
     System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +38
     System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9629296
     System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously) +155
  </code></pre>