diff --git a/src/Umbraco.Core/ApplicationContext.cs b/src/Umbraco.Core/ApplicationContext.cs index b0650653fd..f0f3091c7f 100644 --- a/src/Umbraco.Core/ApplicationContext.cs +++ b/src/Umbraco.Core/ApplicationContext.cs @@ -87,6 +87,18 @@ namespace Umbraco.Core } } + /// + /// The original/first url that the web application executes + /// + /// + /// we need to set the initial url in our ApplicationContext, this is so our keep alive service works and this must + /// exist on a global context because the keep alive service doesn't run in a web context. + /// we are NOT going to put a lock on this because locking will slow down the application and we don't really care + /// if two threads write to this at the exact same time during first page hit. + /// see: http://issues.umbraco.org/issue/U4-2059 + /// + internal string OriginalRequestUrl { get; set; } + private bool Configured { get @@ -127,7 +139,6 @@ namespace Umbraco.Core } } - private void AssertIsReady() { if (!this.IsReady) diff --git a/src/Umbraco.Web.UI/umbraco/ping.aspx b/src/Umbraco.Web.UI/umbraco/ping.aspx index d411738f90..945e59c3f8 100644 --- a/src/Umbraco.Web.UI/umbraco/ping.aspx +++ b/src/Umbraco.Web.UI/umbraco/ping.aspx @@ -1,2 +1,2 @@ -<%@ Page language="c#" Codebehind="ping.aspx.cs" AutoEventWireup="True" Inherits="umbraco.presentation.ping" %> +<%@ Page language="c#" Codebehind="ping.aspx.cs" AutoEventWireup="True" Inherits="System.Web.UI.Page" %> I'm alive! \ No newline at end of file diff --git a/src/Umbraco.Web/LegacyScheduledTasks.cs b/src/Umbraco.Web/LegacyScheduledTasks.cs index 1ebf9d7903..1d09ac0832 100644 --- a/src/Umbraco.Web/LegacyScheduledTasks.cs +++ b/src/Umbraco.Web/LegacyScheduledTasks.cs @@ -35,10 +35,10 @@ namespace Umbraco.Web // of course we should have a proper scheduler, see #U4-809 // ping/keepalive - pingTimer = new Timer(new TimerCallback(global::umbraco.presentation.keepAliveService.PingUmbraco), httpApplication.Context, 60000, 300000); + pingTimer = new Timer(new TimerCallback(global::umbraco.presentation.keepAliveService.PingUmbraco), applicationContext, 60000, 300000); // (un)publishing _and_ also run scheduled tasks (!) - publishingTimer = new Timer(new TimerCallback(global::umbraco.presentation.publishingService.CheckPublishing), httpApplication.Context, 30000, 60000); + publishingTimer = new Timer(new TimerCallback(global::umbraco.presentation.publishingService.CheckPublishing), applicationContext, 30000, 60000); // log scrubbing AddTask(LOG_SCRUBBER_TASK_NAME, GetLogScrubbingInterval()); diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 68d4c3c21b..46acd7198f 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -342,6 +342,9 @@ + + ASPXCodeBehind + ASPXCodeBehind @@ -1408,13 +1411,6 @@ Code - - ping.aspx - ASPXCodeBehind - - - ping.aspx - @@ -2043,9 +2039,6 @@ Form - - Form - Designer diff --git a/src/Umbraco.Web/UmbracoModule.cs b/src/Umbraco.Web/UmbracoModule.cs index 8a4d563ea2..f839c74a17 100644 --- a/src/Umbraco.Web/UmbracoModule.cs +++ b/src/Umbraco.Web/UmbracoModule.cs @@ -10,10 +10,10 @@ using System.Web.Mvc; using System.Web.Routing; using System.Web.UI; using Umbraco.Core; +using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Web.Routing; using umbraco; -using umbraco.IO; using GlobalSettings = Umbraco.Core.Configuration.GlobalSettings; using UmbracoSettings = Umbraco.Core.Configuration.UmbracoSettings; @@ -35,6 +35,16 @@ namespace Umbraco.Web /// void BeginRequest(HttpContextBase httpContext) { + //we need to set the initial url in our ApplicationContext, this is so our keep alive service works and this must + //exist on a global context because the keep alive service doesn't run in a web context. + //we are NOT going to put a lock on this because locking will slow down the application and we don't really care + //if two threads write to this at the exact same time during first page hit. + //see: http://issues.umbraco.org/issue/U4-2059 + if (ApplicationContext.Current.OriginalRequestUrl.IsNullOrWhiteSpace()) + { + ApplicationContext.Current.OriginalRequestUrl = string.Format("{0}:{1}{2}", httpContext.Request.ServerVariables["SERVER_NAME"], httpContext.Request.ServerVariables["SERVER_PORT"], IOHelper.ResolveUrl(SystemDirectories.Umbraco)); + } + // do not process if client-side request if (IsClientSideRequest(httpContext.Request.Url)) return; diff --git a/src/Umbraco.Web/umbraco.presentation/keepAliveService.cs b/src/Umbraco.Web/umbraco.presentation/keepAliveService.cs index 44cca4e7e4..4ab1646a9e 100644 --- a/src/Umbraco.Web/umbraco.presentation/keepAliveService.cs +++ b/src/Umbraco.Web/umbraco.presentation/keepAliveService.cs @@ -2,29 +2,35 @@ using System; using System.Diagnostics; using System.Net; using System.Web; +using Umbraco.Core; +using Umbraco.Core.Logging; namespace umbraco.presentation { /// - /// Summary description for keepAliveService. + /// Makes a call to /umbraco/ping.aspx which is used to keep the web app alive /// public class keepAliveService { + //NOTE: sender will be the umbraco ApplicationContext public static void PingUmbraco(object sender) { - if (sender == null) + if (sender == null || !(sender is ApplicationContext)) return; - string url = string.Format("http://{0}/ping.aspx", ((HttpContext)sender).Application["umbracoUrl"]); + + var appContext = (ApplicationContext) sender; + + var url = string.Format("http://{0}/ping.aspx", appContext.OriginalRequestUrl); try { - using (WebClient wc = new WebClient()) + using (var wc = new WebClient()) { wc.DownloadString(url); } } catch(Exception ee) { - Debug.Write(string.Format("Error in ping({0}) -> {1}", url, ee)); + LogHelper.Debug(string.Format("Error in ping({0}) -> {1}", url, ee)); } } } diff --git a/src/Umbraco.Web/umbraco.presentation/publishingService.cs b/src/Umbraco.Web/umbraco.presentation/publishingService.cs index 163da00565..7f99e0c080 100644 --- a/src/Umbraco.Web/umbraco.presentation/publishingService.cs +++ b/src/Umbraco.Web/umbraco.presentation/publishingService.cs @@ -15,14 +15,15 @@ namespace umbraco.presentation /// public class publishingService { - private static Hashtable scheduledTaskTimes = new Hashtable(); - private static bool isPublishingRunning = false; + private static readonly Hashtable ScheduledTaskTimes = new Hashtable(); + private static bool _isPublishingRunning = false; + //NOTE: sender will be the umbraco ApplicationContext public static void CheckPublishing(object sender) { - if(isPublishingRunning) + if(_isPublishingRunning) return; - isPublishingRunning = true; + _isPublishingRunning = true; try { // DO not run publishing if content is re-loading @@ -33,8 +34,6 @@ namespace umbraco.presentation { try { - //d.HttpContext = (HttpContext)sender; - d.ReleaseDate = DateTime.MinValue; //new DateTime(1, 1, 1); // Causes release date to be null d.Publish(d.User); @@ -52,9 +51,7 @@ namespace umbraco.presentation } foreach(Document d in Document.GetDocumentsForExpiration()) { - //d.HttpContext = (HttpContext)sender; - //d.Published = false; - + try { d.ExpireDate = DateTime.MinValue; @@ -86,20 +83,20 @@ namespace umbraco.presentation foreach (XmlNode task in tasks) { bool runTask = false; - if (!scheduledTaskTimes.ContainsKey(task.Attributes.GetNamedItem("alias").Value)) + if (!ScheduledTaskTimes.ContainsKey(task.Attributes.GetNamedItem("alias").Value)) { runTask = true; - scheduledTaskTimes.Add(task.Attributes.GetNamedItem("alias").Value, DateTime.Now); + ScheduledTaskTimes.Add(task.Attributes.GetNamedItem("alias").Value, DateTime.Now); } // Add 1 second to timespan to compensate for differencies in timer else if ( new TimeSpan(DateTime.Now.Ticks - - ((DateTime) scheduledTaskTimes[task.Attributes.GetNamedItem("alias").Value]).Ticks).TotalSeconds + + ((DateTime) ScheduledTaskTimes[task.Attributes.GetNamedItem("alias").Value]).Ticks).TotalSeconds + 1 >= int.Parse(task.Attributes.GetNamedItem("interval").Value)) { runTask = true; - scheduledTaskTimes[task.Attributes.GetNamedItem("alias").Value] = DateTime.Now; + ScheduledTaskTimes[task.Attributes.GetNamedItem("alias").Value] = DateTime.Now; } if (runTask) @@ -126,13 +123,13 @@ namespace umbraco.presentation } finally { - isPublishingRunning = false; + _isPublishingRunning = false; } } private static bool getTaskByHttp(string url) { - HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url); + var myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url); HttpWebResponse myHttpWebResponse = null; try { diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/ping.aspx b/src/Umbraco.Web/umbraco.presentation/umbraco/ping.aspx deleted file mode 100644 index d411738f90..0000000000 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/ping.aspx +++ /dev/null @@ -1,2 +0,0 @@ -<%@ Page language="c#" Codebehind="ping.aspx.cs" AutoEventWireup="True" Inherits="umbraco.presentation.ping" %> -I'm alive! \ No newline at end of file diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/ping.aspx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/ping.aspx.cs index 21aa5229b5..71d56511e4 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/ping.aspx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/ping.aspx.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections; using System.ComponentModel; using System.Data; @@ -11,40 +11,8 @@ using System.Web.UI.HtmlControls; namespace umbraco.presentation { - /// - /// Summary description for ping. - /// - public partial class ping : System.Web.UI.Page - { - protected void Page_Load(object sender, System.EventArgs e) - { - /* - if (GlobalSettings.DebugMode) - BusinessLogic.Log.Add( - BusinessLogic.LogTypes.Ping, - BusinessLogic.User.GetUser(0), - -1, - ""); - */ - } - - #region Web Form Designer generated code - override protected void OnInit(EventArgs e) - { - // - // CODEGEN: This call is required by the ASP.NET Web Form Designer. - // - InitializeComponent(); - base.OnInit(e); - } - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - } - #endregion - } + [Obsolete("This class is no longer used and will be removed in future versions")] + public partial class ping : System.Web.UI.Page + { + } } diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/ping.aspx.designer.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/ping.aspx.designer.cs deleted file mode 100644 index 7154280a25..0000000000 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/ping.aspx.designer.cs +++ /dev/null @@ -1,15 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:2.0.50727.42 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace umbraco.presentation { - - public partial class ping { - } -}