- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我能够正确利用 ASP.NET MVC4 OutputCache,并将以下代码作为我的 Controller Index() 上的属性:
[OutputCache(Duration = 600, VaryByParam = "none")]
但是,
管理不同的缓存方案,按照 the MSDN documentation 我们可以使用OutputCache缓存(例如)我们的 Controller Index()方法。根据文档,我们最终得到以下代码:
在我们的 Controller
//[OutputCache(Duration = 600, VaryByParam = "none")] //works without any modification to the Web.config
[OutputCache(CacheProfile = "Cache1Hour", VaryByParam = "none")]
public ActionResult Index()
{
return View();
}
和在我们的Web.config
<system.web>
<caching>
<outputCacheSettings>
<outputCacheProfiles>
<add name="Cache1Hour" duration="3600"/>
</outputCacheProfiles>
</outputCacheSettings>
</caching>
...
...
...
</system.web>
问题:显然我遗漏了一些东西,因为我不断抛出以下异常:
异常详细信息:System.Web.HttpException:未定义“Cache1Hour”缓存配置文件。请在配置文件中定义。
完全异常(exception):
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
最佳答案
我发现我将配置代码放置在“ View ”的 Web.config 中,而不是根 Web.config 中。一旦我放置:
<system.web>
<caching>
<outputCacheSettings>
<outputCacheProfiles>
<add name="Cache1Hour" duration="3600"/>
</outputCacheProfiles>
</outputCacheSettings>
</caching>
...
...
...
</system.web>
...进入正确的 Web.config,该方法已正确缓存,我希望这对其他人有帮助。如果没有别的,我在这篇文章中显示的代码和策略为您提供了使用 OutputCache 在 Controller 中缓存方法的最低要求。
关于ASP.NET MVC4 - OutputCache 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16255451/
我很困惑... re this和 this “元”问题... 一个非常基本的http请求: GET http://stackoverflow.com/feeds/tag?tagnames=c%23&s
protected void Page_Load(object sender, EventArgs e) {Label1.Text = DateTime.Now.ToString();} 如果在我编译
在我的应用程序中,我会记住用户在 session 中选择的语言。问题是如果我使用输出缓存,那么更改语言功能将不起作用,因为当我根据 Session["lang"] 值从数据库中检索时它会缓存结果。 那
OutputCache is an easy way to improve performance在 ASP.NET <=4.6 MVC 中。我们应该将此属性应用于非常昂贵的操作,但在第一个请求和正在
我正在使用 OutputCache 属性 [OutputCache(Duration = 3600)] 来缓存返回 View 的 Controller 。但是该 View 包含一个 Helper 方法
我在 ASP.NET 4.0 Webforms 应用程序 (IIS 7.5) 上使用一个非常简单的输出缓存指令,该指令将页面缓存 1 小时。该应用程序没有任何内存压力,但页面在一小时之前就过期了。我创
我的 Controller 方法有以下缓存属性: [CacheOutput(ClientTimeSpan = 14400, ServerTimeSpan = 14400)] 我正在尝试清除缓存。然而
我在 ASP.net MVC 应用程序中使用 OutputCache。由于使用事件的 OutputCache 进行开发并不是很愉快,因此我想禁用开发系统(本地计算机和开发服务器)上的 OutputCa
我是一个为应用程序创建菜单的部分页面。我正在使用 renderaction 调用菜单部分 View 。我想通过这样做将这个部分页面存储在客户端 [OutputCache(Duration=7200,
我在某处读到,对于高流量站点(我想这也是一个模糊的术语),30 - 60 秒是一个不错的值。显然我可以进行负载测试并改变值,但我找不到任何类型的文档。大多数样本只有一分钟,几分钟。没有推荐范围。 ms
我正在尝试在我的 MVC 应用程序中使用 OutputCache 属性,但当我使用 OutputCacheLocation.Client 时它似乎不起作用: public class HomeCont
我在 MVC 5 中使用 OutputCache 来缓存服务器上的 View 。 我只想根据查询字符串中的两个参数缓存一个 View 。 操作方法 [HttpGet] [OutputCache(Loc
我遇到了一些奇怪的缓存问题,并将一个非常简单的 .NET 页面与输出缓存指令放在一起。但是,页面没有缓存(每次刷新时内容都会更新)。 我在我的本地机器(Windows 7)上安装了一个简单的、最小的
有人可以帮助解释什么是 OutputCache VaryByContentEncoding 的用途,或者更好地举例说明其用法。 我知道这与编码压缩有关。它会根据特定的压缩方案缓存不同的响应吗?我在网上
如果我将以下内容添加到我的应用程序/ Controller [OutputCache(Duration = 7200)] 我在网站上有两个用户,User1 和 User2。如果User1浏览到打开上述
假设我有一个页面请求,如下所示 http://localhost/accounting/products?id=234 有时它是这样的: http://localhost/accounting/pro
我能够正确利用 ASP.NET MVC4 OutputCache,并将以下代码作为我的 Controller Index() 上的属性: [OutputCache(Duration = 600, Va
对于我当前的项目,有必要生成动态 CSS... 所以,我有一个充当 CSS 交付者的部分 View ... Controller 代码如下所示: [OutputCache(CacheProfi
我不确定是什么原因造成的,但我们的 Controller 操作用于缓存其输出,但现在不再这样做了: [HttpGet] [OutputCache(VaryByParam = "slug", Durat
是否可以迭代 OutputCache 键?我知道您可以通过 HttpResponse.RemoveOutputCacheItem() 单独删除它们,但是有没有一种方法可以迭代所有键以查看集合中的内容?
我是一名优秀的程序员,十分优秀!