我正在寻找一种检查页面(不是会话)是否过期的方法,如果是,则将它们重定向到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);
}
我看不到页面本身渲染任何缓存或过期属性/标签。不确定是否应该
//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.
}