我今天遇到了一个奇怪的问题,对我来说毫无意义。这是一个摘要:
在一个方法中,我检查缓存项,如下所示:
private async Task<RatesStatus> getRatesStatusAsync() {
//...
if (_currentHttpContext != null) {
//Here, I am checking for a Cached item
var cachedRatesStatusObj = HttpContext.Current.Cache[Constants.RATESSTATUS_CACHE_KEY_NAME];
if (cachedRatesStatusObj != null)
return (RatesStatus)cachedRatesStatusObj;
}
//...
cacheRatesStatusObject(ratesStatus);
//...
}
在这里,在HttpContext.Current
ASP.NET 应用程序中,它不是预期的 null。然后,在cacheRatesStatusObject
方法内部,我检查是否HttpContext.Current
为空,如下所示:
private void cacheRatesStatusObject(RatesStatus ratesStatus) {
//...
//Seeing if HttpContext.Current is null or not first.
//and it is null here...
if (HttpContext.Current == null)
return;
//...
}
它在那里是空的。不知道这里发生了什么。有什么想法吗?