c# - how to set Response.Cache in abstract class
问题描述
I have this abstract class
public abstract class TestControllerBase {
}
and a class
public class TestController : TestControllerBase {
public ActionResult Index()
{
Response.Cache.SetCacheability(HttpCacheability.Public);
Response.Cache.SetExpires(DateTime.Now.AddHours(1));
}
}
how can i set Response.Cache in the abstract class without excplicit calling something in this abstract class. I have like 200 inheritence on the abstract class. So i want to set the cache in one place not in every controller
Regards
解决方案
您可以使用以下代码:
public abstract class TestControllerBase
{
public virtual ActionResult Index()
{
Response.Cache.SetCacheability(HttpCacheability.Public);
Response.Cache.SetExpires(DateTime.Now.AddHours(1));
}
}
public class TestController : TestControllerBase
{
}
public class TestController2 : TestControllerBase
{
public override ActionResult Index()
{
// Do my own stuff
base.Index();
}
}
推荐阅读
- node.js - 附加节点获取文件
- c - 删除包含相同对象的单独链接列表时避免双重 free() 错误
- view - Laravel Voyager:如何解决 Route not defined 问题?
- java - Apache Camel,通过 xslt-saxon 合并 XML 文档的问题
- spring-mvc - MissingServletRequestParameterException:必需的产品参数“产品”不存在
- performance - 如何在 Android Studio 中提高屏幕分辨率?
- neo4j - 子图上的 CYPHER 递归计算
- oracle - UTL_SMTP 试图附加多个大于 32k 的文件
- excel - 比较两列,如果另一列等于指定文本,则返回其中一列的值
- json - 无法使用 jolt 转换器将 stringfy json 对象数组转换为 json 对象