From 67996cdb64427b4b5230ebf41aed8b442a5de522 Mon Sep 17 00:00:00 2001 From: Stephan Date: Wed, 4 May 2016 08:45:50 +0200 Subject: [PATCH] U4-8406 - restart app pool by unloading domain and support read-only web.config --- .../ApplicationContextExtensions.cs | 34 ++++++++----------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/src/Umbraco.Web/ApplicationContextExtensions.cs b/src/Umbraco.Web/ApplicationContextExtensions.cs index fcbcab1628..1756da5f3c 100644 --- a/src/Umbraco.Web/ApplicationContextExtensions.cs +++ b/src/Umbraco.Web/ApplicationContextExtensions.cs @@ -1,30 +1,24 @@ -using System; -using System.IO; -using System.Web; +using System.Web; using Umbraco.Core; namespace Umbraco.Web { public static class ApplicationContextExtensions { - /// - /// This will restart the application pool - /// - /// - /// - public static void RestartApplicationPool(this ApplicationContext appContext, HttpContextBase http) - { + /// + /// Restarts the application pool by unloading the application domain. + /// + /// + /// + public static void RestartApplicationPool(this ApplicationContext appContext, HttpContextBase http) + { + // we're going to put an application wide flag to show that the application is about to restart. + // we're doing this because if there is a script checking if the app pool is fully restarted, then + // it can check if this flag exists... if it does it means the app pool isn't restarted yet. + http.Application.Add("AppPoolRestarting", true); - //we're going to put an application wide flag to show that the application is about to restart. - //we're doing this because if there is a script checking if the app pool is fully restarted, then - //it can check if this flag exists... if it does it means the app pool isn't restarted yet. - http.Application.Add("AppPoolRestarting", true); - - //NOTE: this real way only works in full trust :( - //HttpRuntime.UnloadAppDomain(); - //so we'll do the dodgy hack instead - var configPath = http.Request.PhysicalApplicationPath + "\\web.config"; - File.SetLastWriteTimeUtc(configPath, DateTime.UtcNow); + // unload app domain + HttpRuntime.UnloadAppDomain(); } } }