如何避免缓存_Layout?

时间:2015-11-28 12:43:20

标签: c# asp.net-mvc asp.net-mvc-4 caching

我使用一个属性在我的项目中设置_Layout,并使用一些缓存属性来缓存一些数据。

我的自定义布局属性代码如下:

public class CustomLayoutAttribute : ActionFilterAttribute, IResultFilter
{
    public override void OnResultExecuting(ResultExecutingContext filterContext)
    {
        var viewResult = filterContext.Result as ViewResult;
        string layoutName = "";
        if (viewResult != null)
        {
            switch (SystemInfo.Theme)
            {
                case 1:
                    layoutName = "~/Views/Shared/Layouts/Themes/B/_LayoutMain-En.cshtml";
                    break;
                case 2:
                    layoutName = "~/Views/Shared/Layouts/Themes/A/_LayoutMain-En.cshtml";
                    break;
                }
            }

            viewResult.MasterName = layoutName;
        }
    }
}

布局和缓存属性在Controller Action方法中如下所示:

[CustomLayout]
[OutputCache(Duration = 60 * 10, VaryByParam = "none", VaryByCustom = "lang")]
public ActionResult Index() { }

如何禁用_Layout的缓存?

0 个答案:

没有答案