{"id":2381,"date":"2022-08-30T15:24:23","date_gmt":"2022-08-30T15:24:23","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/01\/05\/asp-net-mvc-hangs-when-returning-view-after-performing-some-web-request-response-tasks-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:24:23","modified_gmt":"2022-08-30T15:24:23","slug":"asp-net-mvc-hangs-when-returning-view-after-performing-some-web-request-response-tasks-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/asp-net-mvc-hangs-when-returning-view-after-performing-some-web-request-response-tasks-collection-of-common-programming-errors\/","title":{"rendered":"ASP.NET MVC hangs when returning View() after performing some web request\/response tasks-Collection of common programming errors"},"content":{"rendered":"<p>I have a controller action called UpdateSite(), browsing to this action is a manual way for me to kick off a (normally automated) data-collection process.<\/p>\n<p>It&#8217;s a fairly simple process which has the following work flow:<\/p>\n<ol>\n<li>Perform a couple of web requests for data using a web API<\/li>\n<li>Parse this data to extract anything I might need<\/li>\n<li>If some of the data is new and relevant, store it in a DB (using linq to sql)<\/li>\n<li>(optionally) send some data back to the API to let it know what I&#8217;ve just done.<\/li>\n<\/ol>\n<p>Here&#8217;s a contrived example of the method:<\/p>\n<pre><code>public ActionResult UpdateSite(string key)\n        {\n            if(key == KEY)\n            {\n                log4net.Config.XmlConfigurator.Configure();\n                ILog log = LogManager.GetLogger(\"Default\");\n                string tUserName = ConfigurationManager.AppSettings[\"UName\"];\n                string tPassword = ConfigurationManager.AppSettings[\"UPassword\"];\n\n                ApiService apiSvc = new ApiService(tUserName, tPassword, new InterpreterFactory(),\n                                                                    log);\n                ControlPanel controller = new ControlPanel(Service, apiSvc, new DefaultAppStatusService(), log);\n\n                CaptureResults results = controller.Capture();\n                controller.EnrichData(results, new EnrichmentFactory(log));\n\n                var newData = controller.PersistData(results);\n                controller.ReplyWithNewData(newData);\n            }\n            return View();\n        }\n<\/code><\/pre>\n<p>All this seems to run fine, it does its stuff, pulls back the data it needs from the external API writes it to the database etc.<\/p>\n<p>The problem is that on &#8220;return View()&#8221; the page doesn&#8217;t fully load in the browser and the site hangs permanently forcing me to restart the dev server. All the page has on it is a bit of text.<\/p>\n<p>I have absolutely no idea what is going on. Has anyone else encountered something like this? Any ideas what it could be?<\/p>\n<ol>\n<li>\n<p>Does it happen that this process alters some file in the bin folder or any of its subfolders? If so it will recycle the AppPool and the request will &#8220;crash&#8221; with no chance.<\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2014-01-05 22:38:36. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I have a controller action called UpdateSite(), browsing to this action is a manual way for me to kick off a (normally automated) data-collection process. It&#8217;s a fairly simple process which has the following work flow: Perform a couple of web requests for data using a web API Parse this data to extract anything I [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2381","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2381","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=2381"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2381\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2381"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2381"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2381"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}