{"id":36821,"date":"2019-05-24T06:00:25","date_gmt":"2019-05-24T13:00:25","guid":{"rendered":"http:\/\/devblogs.microsoft.com\/premier-developer\/?p=36821"},"modified":"2019-05-24T19:41:12","modified_gmt":"2019-05-25T02:41:12","slug":"404-response-code-caused-by-app-services-alwayson-feature","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/premier-developer\/404-response-code-caused-by-app-services-alwayson-feature\/","title":{"rendered":"404 response code caused by App Services \u2013 AlwaysOn feature"},"content":{"rendered":"<p>In this post, Sr. Consultant <a href=\"https:\/\/www.linkedin.com\/in\/adel-ghabboun-44082916\/\">Adel Ghabboun<\/a> shows how to optimize Azure App Service against cold starts using AlwaysOn.<\/p>\n<hr \/>\n<p><strong>Use case:<\/strong><\/p>\n<ul>\n<li><a href=\"https:\/\/azure.microsoft.com\/updates\/azure-web-sites-adds-always-on\/\">Azure App service<\/a> with <em>AlwaysOn<\/em> feature = <strong>True<\/strong> (See below screenshot)<\/li>\n<li>Traffic Manager and Application Gateway are used, which relay on health probes to determine the availability and health of the App Service<\/li>\n<li>Application Insights for monitoring<\/li>\n<\/ul>\n<p><img decoding=\"async\" width=\"1146\" height=\"564\" class=\"wp-image-36822\" src=\"http:\/\/devblogs.microsoft.com\/premier-developer\/wp-content\/uploads\/sites\/31\/2019\/05\/word-image-33.png\" srcset=\"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-content\/uploads\/sites\/31\/2019\/05\/word-image-33.png 1146w, https:\/\/devblogs.microsoft.com\/premier-developer\/wp-content\/uploads\/sites\/31\/2019\/05\/word-image-33-300x148.png 300w, https:\/\/devblogs.microsoft.com\/premier-developer\/wp-content\/uploads\/sites\/31\/2019\/05\/word-image-33-768x378.png 768w, https:\/\/devblogs.microsoft.com\/premier-developer\/wp-content\/uploads\/sites\/31\/2019\/05\/word-image-33-1024x504.png 1024w\" sizes=\"(max-width: 1146px) 100vw, 1146px\" \/><\/p>\n<p><strong>Symptoms:<\/strong><\/p>\n<ul>\n<li>App Service <em>Always On<\/em> also generate periodic (every 5min) probes to app instances and causing failed requests with error <strong>404<\/strong>, and this can be found in Application Insights as below<\/li>\n<\/ul>\n<p><img decoding=\"async\" width=\"776\" height=\"465\" class=\"wp-image-36823\" src=\"http:\/\/devblogs.microsoft.com\/premier-developer\/wp-content\/uploads\/sites\/31\/2019\/05\/word-image-34.png\" srcset=\"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-content\/uploads\/sites\/31\/2019\/05\/word-image-34.png 776w, https:\/\/devblogs.microsoft.com\/premier-developer\/wp-content\/uploads\/sites\/31\/2019\/05\/word-image-34-300x180.png 300w, https:\/\/devblogs.microsoft.com\/premier-developer\/wp-content\/uploads\/sites\/31\/2019\/05\/word-image-34-768x460.png 768w\" sizes=\"(max-width: 776px) 100vw, 776px\" \/><\/p>\n<p><img decoding=\"async\" width=\"622\" height=\"376\" class=\"wp-image-36824\" src=\"http:\/\/devblogs.microsoft.com\/premier-developer\/wp-content\/uploads\/sites\/31\/2019\/05\/word-image-35.png\" srcset=\"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-content\/uploads\/sites\/31\/2019\/05\/word-image-35.png 622w, https:\/\/devblogs.microsoft.com\/premier-developer\/wp-content\/uploads\/sites\/31\/2019\/05\/word-image-35-300x181.png 300w\" sizes=\"(max-width: 622px) 100vw, 622px\" \/><\/p>\n<p><strong>Solution:<\/strong><\/p>\n<p>This can be fixed by rewriting the <em>Always on<\/em> path. After a cold start of your application, AlwaysOn will send a request to the ROOT of your application \u201c\/\u201d.\u00a0 Whatever file is delivered when a request is made to \/ is the one which will be warmed up, which will fail because the root doesn\u2019t exist.<\/p>\n<p>If you wanted AlwaysOn to warmup a specific page instead of the root, then you can implement this URL Rewrite rule.<\/p>\n<table>\n<tbody>\n<tr>\n<td>\n<pre class=\"lang:default decode:true \">&lt;?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"&gt;\r\n&lt;configuration&gt;\r\n    &lt;system.webServer&gt;\r\n      &lt;rewrite&gt;\r\n        &lt;rules&gt;\r\n          &lt;rule name=\"Rewrite AlwaysOn\" stopProcessing=\"true\"&gt;\r\n            &lt;match url=\"^$\" \/&gt;\r\n            &lt;conditions&gt;\r\n              &lt;add input=\"{HTTP_USER_AGENT}\" pattern=\"^AlwaysOn$\" \/&gt;\r\n            &lt;\/conditions&gt;\r\n            &lt;action type=\"Rewrite\" url=\"\/api\/Online\/Ping\" \/&gt;\r\n          &lt;\/rule&gt;\r\n        &lt;\/rules&gt;\r\n      &lt;\/rewrite&gt;\r\n    &lt;\/system.webServer&gt;\r\n&lt;\/configuration&gt;<\/pre>\n<p>&nbsp;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p>Please refer <a href=\"https:\/\/blogs.msdn.microsoft.com\/benjaminperkins\/2018\/08\/10\/how-to-optimize-azure-app-service-alwayson-cold-start-warm-up-request\/\">here<\/a> for more details.<\/p>\n<p>Something to note here that if you are already using <a href=\"https:\/\/docs.microsoft.com\/azure\/traffic-manager\/\"><strong>Azure<\/strong> <strong>Traffic Manager<\/strong><\/a> service with a health probe periodically pinging the site\/path, AlwaysOn would be redundant as the web app will be kept warm by the health probes.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this post, Sr. Consultant Adel Ghabboun shows how to optimize Azure App Service Always against cold starts.<\/p>\n","protected":false},"author":582,"featured_media":36823,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[25,1,55],"tags":[24,3],"class_list":["post-36821","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-azure","category-permierdev","category-web","tag-azure","tag-team"],"acf":[],"blog_post_summary":"<p>In this post, Sr. Consultant Adel Ghabboun shows how to optimize Azure App Service Always against cold starts.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/posts\/36821","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/users\/582"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/comments?post=36821"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/posts\/36821\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/media\/36823"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/media?parent=36821"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/categories?post=36821"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/tags?post=36821"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}