对于 .net 4 中的函数

发布于 2024-08-28 21:05:28 字数 288 浏览 1 评论 0原文

我在 Scottgu 关于使用 OutputCache 实现功能的博客,但这对我不起作用。如何将 [OutputCache(Duration=60)] 用于函数?我可以在此语句中添加 VaryByParam 吗?需要哪个命名空间?

I read at Scottgu blog about using OutputCache for a function but this didn't worked for me. How can I use [OutputCache(Duration=60)] for a function and can I add VaryByParam in this statement? Which namespace is required?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时光病人 2024-09-04 21:05:28

OutputCacheAttribute 类是 < href="http://msdn.microsoft.com/en-us/library/system.web.mvc.aspx" rel="nofollow noreferrer">System.Web.MVC 命名空间。您可以将 VaryByParam 与它一起使用:

<OutputCache(Duration:=60, VaryByParam:="Any")> _
Function Index() As ActionResult
    ViewData("Message") = "Welcome to ASP.NET MVC!"

    Return View()
End Function

但我猜您只能将其应用于返回 ActionResult 的 MVC 方法 - 我认为您不能在 WebForms 项目中使用它(我是从你的问题猜测你正在使用什么)。

The OutputCacheAttribute class is part of the System.Web.MVC namespace. You can use VaryByParam with it:

<OutputCache(Duration:=60, VaryByParam:="Any")> _
Function Index() As ActionResult
    ViewData("Message") = "Welcome to ASP.NET MVC!"

    Return View()
End Function

but I would guess that you can only apply it to MVC methods that return an ActionResult - I don't think you could use it in a WebForms project (which I'm guessing from your question is what you're using).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文