检查PAGE是否已过期,然后重定向

时间:2014-01-28 00:28:24

标签: asp.net-mvc

我正在寻找一种方法来检查PAGE(NOT会话)是否过期,如果是,将它们重定向到MVC(4)中的另一个视图?如果页面已过期,我不打算重新加载页面而是显示浏览器“此页面已过期”页面,而是执行类似重新执行控制器操作但检查该页面是否已过期的操作

任何想法?

更新:代码:

public override void OnResultExecuting(ResultExecutingContext filterContext)
        {
            filterContext.HttpContext.Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-60));
            filterContext.HttpContext.Response.Cache.SetValidUntilExpires(true);
            filterContext.HttpContext.Response.Cache.SetCacheability(HttpCacheability.NoCache);
            filterContext.HttpContext.Response.Cache.SetNoStore();
            filterContext.HttpContext.Response.Cache.SetAllowResponseInBrowserHistory(false);

            base.OnResultExecuting(filterContext);
        }

我没有看到页面本身呈现任何没有缓存或expires属性/标签。不确定是否应该

1 个答案:

答案 0 :(得分:0)

//This is a sample for callback on cache expiration.
 string test = "test1";
 Cache.Insert("Key", test, dependancy, DateTime.Now.AddMinutes(DateTime.Now),    System.Web.Caching.Cache.NoSlidingExpiration, CacheItemPriority.High, new CacheItemRemovedCallback(CacheRemovedCallback));

    public void CacheRemovedCallback(String key, object value, System.Web.Caching.CacheItemRemovedReason removedReason)
    {
        //Logs.write = "Cache Expired for : " + key;
        RedirectToAction("action","controller");
        //You can redirect or do anything else you want.
    }