相关疑难解决方法(0)

禁用整个ASP.NET网站的浏览器缓存

我正在寻找一种方法来禁用整个ASP.NET MVC网站的浏览器缓存

我找到了以下方法:

Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);
Response.Cache.SetNoStore();
Run Code Online (Sandbox Code Playgroud)

还有一个元标记方法(它对我不起作用,因为一些MVC动作通过Ajax发送部分HTML/JSON,没有头部元标记).

<meta http-equiv="PRAGMA" content="NO-CACHE">
Run Code Online (Sandbox Code Playgroud)

但我正在寻找一种简单的方法来禁用整个网站的浏览器缓存.

asp.net asp.net-mvc caching browser-cache

199
推荐指数
5
解决办法
13万
查看次数

使用缓存配置文件缓存ChildActions不起作用?

我正在尝试使用缓存配置文件缓存我的mvc应用程序中的子操作,但我得到一个例外:持续时间必须是正数.

我的web.config看起来像这样:

<caching>
      <outputCache enableOutputCache="true" />
      <outputCacheSettings>
        <outputCacheProfiles>
          <add name="TopCategories" duration="3600" enabled="true" varyByParam="none" />
        </outputCacheProfiles>
      </outputCacheSettings>
</caching>
Run Code Online (Sandbox Code Playgroud)

而我的孩子的动作是这样的:

[ChildActionOnly]
[OutputCache(CacheProfile = "TopCategories")]
//[OutputCache(Duration = 60)]
public PartialViewResult TopCategories()
{
    //...
    return PartialView();
}
Run Code Online (Sandbox Code Playgroud)

我只是打电话给一个视图 @Html.RenderAction("TopCategories", "Category")

但是我收到一个错误:Exception Details:System.InvalidOperationException:Duration必须是一个正数.

如果我不使用缓存配置文件,它的工作原理.知道问题是什么?

asp.net-mvc caching

17
推荐指数
2
解决办法
1万
查看次数

MVC HTML.RenderAction - 错误:持续时间必须是正数

在我的网站上,我希望用户能够从任何页面登录/注销.当用户选择登录按钮时,将向用户提供模态对话框以供他输入他的凭证.

由于登录将在每个页面上,我想我会为登录创建一个局部视图并将其添加到布局页面.但是当我这样做时,我得到以下错误: 异常详细信息:System.InvalidOperationException:持续时间必须是正数.

还有其他解决方法,不使用部分视图,但我相信这应该工作.

因此,为了测试这一点,我决定使用以下代码使一切变得简单:

使用以下代码创建布局页面

@{Html.RenderAction("_Login", "Account");}
Run Code Online (Sandbox Code Playgroud)

在AccountController中:

public ActionResult _Login()
{
    return PartialView("_Login");
}
Run Code Online (Sandbox Code Playgroud)

部分视图_Login

<a id="signin">Login</a>
Run Code Online (Sandbox Code Playgroud)

但是当我运行这个简单版本时,我仍然会收到此错误: 异常详细信息:System.InvalidOperationException:Duration必须是正数.

错误来源指向"@ {Html.RenderAction("_ Login","Account");}"

网上有一些类似于我的问题的对话,它将此识别为MVC的错误(参见下面的链接).但链接属于缓存,我没有做任何缓存.

OuputCache缓存配置文件不适用于子操作
http://aspnet.codeplex.com/workitem/7923

Asp.Net MVC 3部分页面输出缓存不符合配置设置 Asp.Net MVC 3部分页面输出缓存不符合配置设置

使用缓存配置文件缓存ChildActions不起作用? 使用缓存配置文件缓存ChildActions不起作用?

我不确定这是否有所作为,但我会继续在这里添加它.我正在使用带有Razor的MVC 3.


更新
堆栈跟踪

[InvalidOperationException: Duration must be a positive number.]
   System.Web.Mvc.OutputCacheAttribute.ValidateChildActionConfiguration() +624394
   System.Web.Mvc.OutputCacheAttribute.OnActionExecuting(ActionExecutingContext filterContext) +127
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +72
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +784922
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +314
   System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +784976
   System.Web.Mvc.Controller.ExecuteCore() …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc razor asp.net-mvc-3

15
推荐指数
1
解决办法
3万
查看次数