'Not able to resolve "The underlying connection was closed: An unexpected error occurred on a send" in .NET
I sometimes see this error on my page "The underlying connection was closed: An unexpected error occurred on a send" and I am not really sure what the problem is because it's a on and off issue. I am able to see the data in the browser just fine. There are times were I don't see this error and then there are times I do.
Here is the code snippet where I believe the error is coming from.
@using Newtonsoft.Json.Linq;
@{
string myLayout = ViewData["myLayout"].ToString();
IEnumerable<ICMSElement> myCollection = Model.Elements("GalleryImage");
bool containGallery = myCollection != null && myCollection.Count() > 0 && !myCollection.FirstOrDefault().Value.IsNullOrEmpty();
JArray myFeatureJSON = null;
IEnumerable<JToken> featureSet = null;
if (Cache["myFeatures"] == null)
{
WebClient getmyFeatures = new WebClient();
try
{
string myFeatures = getmyFeatures.DownloadString(new Uri("https://data........."));
myFeatureJSON = Newtonsoft.Json.JsonConvert.DeserializeObject(myFeatures) as JArray;
Cache.Insert("myFeatures", myFeatureJSON, null, System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(10));
}
catch (Exception featureError)
{
Response.Write(featureError.Message);
}
}
else
{
myFeatureJSON = (JArray)Cache["myFeatures"];
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
