Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ASP.NET MVC4-输出缓存异常_Asp.net_Asp.net Mvc 4_Outputcache - Fatal编程技术网

ASP.NET MVC4-输出缓存异常

ASP.NET MVC4-输出缓存异常,asp.net,asp.net-mvc-4,outputcache,Asp.net,Asp.net Mvc 4,Outputcache,我能够适当地利用ASP.NETMVC4 OutputCache,并将以下代码作为控制器索引()上的属性: 但是, 为了管理不同的缓存场景,根据我们可以使用OutputCache缓存(例如)控制器Index()方法。根据文档,我们最终得到以下代码: 在我们的控制器中 和在我们的Web.config中 ... ... ... 问题/问题:显然,我在不断抛出以下异常时遗漏了一些内容: 异常详细信息:System.Web.HttpException:未定义“Cache1Hour”缓存配置文件。请在配

我能够适当地利用ASP.NETMVC4 OutputCache,并将以下代码作为控制器索引()上的属性:

但是,

为了管理不同的缓存场景,根据我们可以使用OutputCache缓存(例如)控制器Index()方法。根据文档,我们最终得到以下代码:

在我们的控制器中

在我们的Web.config中


...
...
...
问题/问题:显然,我在不断抛出以下异常时遗漏了一些内容:

异常详细信息:System.Web.HttpException:未定义“Cache1Hour”缓存配置文件。请在配置文件中定义它

完全异常:

“/”应用程序中出现服务器错误。 未定义“Cache1Hour”缓存配置文件。请在配置文件中定义它。 描述:执行当前web请求期间发生未处理的异常。请查看堆栈跟踪以了解有关错误的更多信息以及错误在代码中的起源。 异常详细信息:System.Web.HttpException:未定义“Cache1Hour”缓存配置文件。请在配置文件中定义它。 源错误: 在执行当前web请求期间生成了未经处理的异常。有关异常的起源和位置的信息可以使用下面的异常堆栈跟踪来识别。 堆栈跟踪: [HttpException(0x80004005):未定义“Cache1Hour”缓存配置文件。请在配置文件中定义它。] System.Web.UI.Page.InitOutputCache(OutputCacheParameters缓存设置)+3136900 System.Web.Mvc.OutputCachedPage.FrameworkInitialize()+47 System.Web.UI.Page.ProcessRequest(布尔值includeStagesBeforeAsyncPoint,布尔值IncludeStagesSafteraSyncpoint)+48 System.Web.UI.Page.ProcessRequest()+72 System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext上下文)+21 System.Web.UI.Page.ProcessRequest(HttpContext上下文)+58 System.Web.Mvc.OutputCacheAttribute.OnResultExecuting(ResultExecutingContext filterContext)+184 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter筛选器,ResultExecutingContext预文本,Func`1 continuation)+72 System.Web.Mvc.c__DisplayClass1c.b__19()+72 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter筛选器,ResultExecutingContext预文本,Func`1 continuation)+388 System.Web.Mvc.c__DisplayClass1c.b__19()+72 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext ControllerContext,IList`1过滤器,ActionResult ActionResult)+303 System.Web.Mvc.Async.c__DisplayClass2a.b__20()+155 System.Web.Mvc.Async.c__显示类25.b__22(IAsyncResult asyncResult)+184 System.Web.Mvc.Async.WrappedAsyncResult`1.End()+136 System.Web.Mvc.Async.asyncResultRapper.End(IAsyncResult asyncResult,对象标记)+56 System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult)+40 System.Web.Mvc.c_uuudisplayClassId.b_uuu18(IAsyncResult asyncResult)+40 System.Web.Mvc.Async.c__显示类4.b__3(IAsyncResult ar)+47 System.Web.Mvc.Async.WrappedAsyncResult`1.End()+151 System.Web.Mvc.Async.asyncResultRapper.End(IAsyncResult asyncResult,对象标记)+59 System.Web.Mvc.Async.asyncResultRapper.End(IAsyncResult asyncResult,对象标记)+40 System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult)+44 System.Web.Mvc.Async.c__显示类4.b__3(IAsyncResult ar)+47 System.Web.Mvc.Async.WrappedAsyncResult`1.End()+151 System.Web.Mvc.Async.asyncResultRapper.End(IAsyncResult asyncResult,对象标记)+59 System.Web.Mvc.Async.asyncResultRapper.End(IAsyncResult asyncResult,对象标记)+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.c_uuuudisplayClass8.b_uuuu3(IAsyncResult asyncResult)+45 System.Web.Mvc.Async.c__显示类4.b__3(IAsyncResult ar)+47 System.Web.Mvc.Async.WrappedAsyncResult`1.End()+151 System.Web.Mvc.Async.asyncResultRapper.End(IAsyncResult asyncResult,对象标记)+59 System.Web.Mvc.Async.asyncResultRapper.End(IAsyncResult asyncResult,对象标记)+40 System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)+40 System.Web.Mvc.MvcHandler.System.Web.IHTTPassynchandler.EndProcessRequest(IAsyncResult结果)+38 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()+96296 System.Web.HttpApplication.ExecuteStep(IExecutionStep步骤,布尔值&同步完成)+155
我发现我将配置代码放在了'View'的Web.config中,而不是根Web.config中。一旦我放置:

<system.web>
    <caching>
      <outputCacheSettings>
          <outputCacheProfiles>
              <add name="Cache1Hour" duration="3600"/>
          </outputCacheProfiles>
      </outputCacheSettings>
    </caching>
    ...
    ...
    ...
</system.web>   

...
...
...
…将该方法正确缓存到正确的Web.config中,我希望这对其他人有所帮助。如果没有其他内容,我在本文中展示的代码和策略为您提供了使用OutputCache在控制器中缓存方法的最低要求

    //[OutputCache(Duration = 600, VaryByParam = "none")] //works without any modification to the Web.config
    [OutputCache(CacheProfile = "Cache1Hour", VaryByParam = "none")]
    public ActionResult Index()
    {
        return View();
    }
  <system.web>
    <caching>
      <outputCacheSettings>
          <outputCacheProfiles>
              <add name="Cache1Hour" duration="3600"/>
          </outputCacheProfiles>
      </outputCacheSettings>
    </caching>
            ...
            ...
            ...
  </system.web>
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.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +72
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +388
   System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +72
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +303
   System.Web.Mvc.Async.<>c__DisplayClass2a.<BeginInvokeAction>b__20() +155
   System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>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.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +40
   System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>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.<>c__DisplayClass4.<MakeVoidDelegate>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.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +45
   System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>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& completedSynchronously) +155
<system.web>
    <caching>
      <outputCacheSettings>
          <outputCacheProfiles>
              <add name="Cache1Hour" duration="3600"/>
          </outputCacheProfiles>
      </outputCacheSettings>
    </caching>
    ...
    ...
    ...
</system.web>