在我的网站上,我希望用户能够从任何页面登录/注销.当用户选择登录按钮时,将向用户提供模态对话框以供他输入他的凭证.
由于登录将在每个页面上,我想我会为登录创建一个局部视图并将其添加到布局页面.但是当我这样做时,我得到以下错误: 异常详细信息: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) 我一直在搜索有关如何在项目级别禁用客户端缓存的信息.我知道我可以在动作方法之前添加以下内容:
[System.Web.Mvc.OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
我还阅读了有关为缓存创建配置文件的内容,但这也意味着在几个地方引用它们.我想在web.config中设置一个设置,或者在IIS中?
我正在研究的项目包含很多部分视图
提前感谢您对此事的任何建议.
我有一个简单的局部视图,我在主视图中渲染:
@Html.Action("All", "Template")
Run Code Online (Sandbox Code Playgroud)
在我的控制器上我有这个:
[OutputCache(CacheProfile = "Templates")]
public ActionResult All()
{
return Content("This stinks.");
}
Run Code Online (Sandbox Code Playgroud)
在我的配置中:
<caching>
<outputCacheSettings>
<outputCacheProfiles>
<clear/>
<add name="Templates" duration="3600" varyByParam="none"/>
</outputCacheProfiles>
</outputCacheSettings>
<outputCache enableOutputCache="false" enableFragmentCache="false" />
</caching>
Run Code Online (Sandbox Code Playgroud)
这将在运行时失败,但有异常:
执行处理程序'System.Web.Mvc.HttpHandlerUtil + ServerExecuteHttpHandlerAsyncWrapper的子请求时出错
内在异常:
持续时间必须是正数
现在显然它没有拿起我的web.config设置,因为如果我将其更改为:
[OutputCache(Duration = 3600)]
Run Code Online (Sandbox Code Playgroud)
它会工作,而且在我的web.config通知我关掉enableOutputCache和enableFragmentCache,但它不支持这些设置.
奇怪的是,在普通视图中这些设置工作正常,那么部分视图是什么打破了这个呢?我错过了什么吗?顾说这应该工作得很好...... 总之,它是否应该尊重web.config中的缓存设置,如果没有,为什么不呢?