1
我正在使用下面的代码来呈现页面并将输出存储在缓存中。所以,在接下来的请求的页面来自缓存(减少处理时间)无法将对象转换回System.web.webpages.HelperResult
HelperResult renderPageResult = null;
try
{
if (objCache.Get(new CacheService().GetKey(cacheKey, _userContext)) == null)
{
renderPageResult = RenderPage(path, data);
objCache.Add(new CacheService().GetKey(cacheKey, _userContext), renderPageResult);
}
else
{
renderPageResult = objCache.Get<HelperResult>(new CacheService().GetKey(cacheKey, _userContext));
}
return renderPageResult;
}
catch(Exception ex)
当转换对象回HelperResult我收到没有得到HTML字符串和UI提示以下例外
价值不在预期范围内。
描述:执行当前Web请求期间发生未处理的异常。请查看堆栈跟踪以获取有关该错误的更多信息以及源代码的位置。
异常详细信息:System.ArgumentException:值不在预期范围内。
哪行代码抛出异常解决了吗? –
有没有例外,但不是html字符串我得到的是对象 –
如果我正确理解你的问题'objCache.Get'方法返回对象,而不是'HelperResult'类的对象。当你试图在UI中渲染它时,你会看到异常。纠正我,如果我错了?你能提供一些你想要达到的内容吗?你在哪里使用'HelperResult'的对象? –