diff --git a/umbraco/presentation/UmbracoContext.cs b/umbraco/presentation/UmbracoContext.cs index 9a42041f50..1b78521edc 100644 --- a/umbraco/presentation/UmbracoContext.cs +++ b/umbraco/presentation/UmbracoContext.cs @@ -90,11 +90,11 @@ namespace umbraco.presentation get { string currentUrl = Request.Url.AbsolutePath; - // zb-00004 #29956 : refactor cookies names & handling - return - StateHelper.Cookies.Preview.HasValue // has preview cookie - && UmbracoUser != null // has user - && !currentUrl.StartsWith(IO.IOHelper.ResolveUrl(IO.SystemDirectories.Umbraco)); // is not in admin UI + // zb-00004 #29956 : refactor cookies names & handling + return + StateHelper.Cookies.Preview.HasValue // has preview cookie + && UmbracoUser != null // has user + && !currentUrl.StartsWith(IO.IOHelper.ResolveUrl(IO.SystemDirectories.Umbraco)); // is not in admin UI } } @@ -105,14 +105,14 @@ namespace umbraco.presentation if (_previewContent == null) { _previewContent = new PreviewContent(new Guid(StateHelper.Cookies.Preview.GetValue())); - _previewContent.LoadPreviewset(); + if (_previewContent.ValidPreviewSet) + _previewContent.LoadPreviewset(); } - return _previewContent.XmlContent; - } - else - { - return content.Instance.XmlContent; + if (_previewContent.ValidPreviewSet) + return _previewContent.XmlContent; } + return content.Instance.XmlContent; + } /// diff --git a/umbraco/presentation/umbraco/preview/Preview.cs b/umbraco/presentation/umbraco/preview/Preview.cs index b1782f6955..f1c0bef257 100644 --- a/umbraco/presentation/umbraco/preview/Preview.cs +++ b/umbraco/presentation/umbraco/preview/Preview.cs @@ -24,6 +24,9 @@ namespace umbraco.presentation.preview public XmlDocument XmlContent { get; set; } public Guid PreviewSet { get; set; } public string PreviewsetPath { get; set; } + + public bool ValidPreviewSet { get; set; } + private int m_userId = 0; public PreviewContent(User user) @@ -54,16 +57,44 @@ namespace umbraco.presentation.preview public PreviewContent(Guid previewSet) { - updatePreviewPaths(previewSet); + ValidPreviewSet = updatePreviewPaths(previewSet); } - private void updatePreviewPaths(Guid previewSet) + private bool updatePreviewPaths(Guid previewSet) { PreviewSet = previewSet; PreviewsetPath = IO.IOHelper.MapPath( Path.Combine(IO.SystemDirectories.Preview, m_userId.ToString() + "_" + PreviewSet + ".config")); + + if (!ValidatePreviewPath()) + { + // preview cookie failed so we'll log the error and clear the cookie + Log.Add(LogTypes.Error, User.GetUser(m_userId), -1, string.Format("Preview failed for preview set {0}", previewSet)); + PreviewSet = Guid.Empty; + PreviewsetPath = String.Empty; + + ClearPreviewCookie(); + + return false; + } + + return true; } + /// + /// Checks a preview file exist based on preview cookie + /// + /// + public bool ValidatePreviewPath() + { + if (!File.Exists(PreviewsetPath)) + return false; + + return true; + } + + + public void LoadPreviewset() { XmlContent = new XmlDocument();