if (System.Web.HttpContext.Current.Cache.Get("dsActiveNews_FixID_" + newsFixID) == null)
news = NewsDB.getNewsBodyByFixID(newsFixID);
System.Web.HttpContext.Current.Cache.Add("dsActiveNews_FixID_" + newsFixID, news, null, DateTime.Now.AddMinutes(60), Cache.NoSlidingExpiration, CacheItemPriority.Normal, null);
}
news = (News)(System.Web.HttpContext.Current.Cache.Get("dsActiveNews_FixID_" + newsFixID));当我第一次调用页面时,转换工作,当我刷新页面时,我得到了一个异常的InvalidCastException: Specified cast is not valid。
发布于 2013-01-18 01:18:06
可能是null /或某个其他对象,无法强制转换,因此获取它并检查它为
var oNews = System.Web.HttpContext.Current.Cache.Get("dsActiveNews_FixID_" + newsFixID) as News;
if(oNews != null)
{
}https://stackoverflow.com/questions/14384290
复制相似问题