Fixes: U4-3638 - U7 - Preview mode seems permanent and shows incorrect content on front of website, when using same browser as admin login
This commit is contained in:
@@ -36,7 +36,7 @@ namespace Umbraco.Core.Configuration.UmbracoSettings
|
||||
return new OptionalInnerTextConfigurationElement<string>(
|
||||
(InnerTextConfigurationElement<string>)this["authCookieName"],
|
||||
//set the default
|
||||
"UMB_UCONTEXT");
|
||||
Constants.Web.AuthCookieName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,5 +23,22 @@
|
||||
public const int RecycleBinMedia = -21;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Defines the identifiers for Umbraco system nodes.
|
||||
/// </summary>
|
||||
public static class Web
|
||||
{
|
||||
/// <summary>
|
||||
/// The preview cookie name
|
||||
/// </summary>
|
||||
public const string PreviewCookieName = "UMB_PREVIEW";
|
||||
|
||||
/// <summary>
|
||||
/// The auth cookie name
|
||||
/// </summary>
|
||||
public const string AuthCookieName = "UMB_UCONTEXT";
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
|
||||
namespace Umbraco.Tests.Configurations.UmbracoSettings
|
||||
{
|
||||
@@ -23,7 +24,7 @@ namespace Umbraco.Tests.Configurations.UmbracoSettings
|
||||
[Test]
|
||||
public void AuthCookieName()
|
||||
{
|
||||
Assert.IsTrue(SettingsSection.Security.AuthCookieName == "UMB_UCONTEXT");
|
||||
Assert.IsTrue(SettingsSection.Security.AuthCookieName == Constants.Web.AuthCookieName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ using System.Security.Principal;
|
||||
using System.Web;
|
||||
using System.Web.Routing;
|
||||
using Moq;
|
||||
using Umbraco.Core;
|
||||
|
||||
namespace Umbraco.Tests.TestHelpers
|
||||
{
|
||||
@@ -58,7 +59,7 @@ namespace Umbraco.Tests.TestHelpers
|
||||
|
||||
//Cookie collection
|
||||
var cookieCollection = new HttpCookieCollection();
|
||||
cookieCollection.Add(new HttpCookie("UMB_UCONTEXT", "FBA996E7-D6BE-489B-B199-2B0F3D2DD826"));
|
||||
cookieCollection.Add(new HttpCookie(Constants.Web.AuthCookieName, "FBA996E7-D6BE-489B-B199-2B0F3D2DD826"));
|
||||
|
||||
//Request
|
||||
var requestMock = new Mock<HttpRequestBase>();
|
||||
|
||||
@@ -255,7 +255,8 @@ function ContentEditController($scope, $routeParams, $q, $timeout, $window, appS
|
||||
$scope.save().then(function(data){
|
||||
$window.open('dialogs/preview.aspx?id='+data.id,'umbpreview');
|
||||
});
|
||||
}else{
|
||||
}
|
||||
else {
|
||||
$window.open('dialogs/preview.aspx?id='+content.id,'umbpreview');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="../masterpages/umbracoDialog.Master" CodeBehind="Preview.aspx.cs" Inherits="umbraco.presentation.dialogs.Preview" %>
|
||||
<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="../masterpages/umbracoDialog.Master" Inherits="umbraco.presentation.dialogs.Preview" %>
|
||||
<%@ Register TagPrefix="cc1" Namespace="umbraco.uicontrols" Assembly="controls" %>
|
||||
|
||||
<asp:Content ID="Content1" ContentPlaceHolderID="body" runat="server">
|
||||
|
||||
@@ -28,6 +28,8 @@ using umbraco;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Dynamics;
|
||||
using umbraco.BusinessLogic.Actions;
|
||||
using umbraco.cms.businesslogic.web;
|
||||
using umbraco.presentation.preview;
|
||||
using Constants = Umbraco.Core.Constants;
|
||||
|
||||
namespace Umbraco.Web.Editors
|
||||
@@ -303,9 +305,29 @@ namespace Umbraco.Web.Editors
|
||||
break;
|
||||
}
|
||||
|
||||
UpdatePreviewContext(contentItem.PersistedContent.Id);
|
||||
|
||||
return display;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the user is currently in preview mode and if so will update the preview content for this item
|
||||
/// </summary>
|
||||
/// <param name="contentId"></param>
|
||||
private void UpdatePreviewContext(int contentId)
|
||||
{
|
||||
var previewId = Request.GetPreviewCookieValue();
|
||||
if (previewId.IsNullOrWhiteSpace()) return;
|
||||
Guid id;
|
||||
if (Guid.TryParse(previewId, out id))
|
||||
{
|
||||
var d = new Document(contentId);
|
||||
var pc = new PreviewContent(UmbracoUser, id, false);
|
||||
pc.PrepareDocument(UmbracoUser, d, true);
|
||||
pc.SavePreviewSet();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Maps the dto property values to the persisted model
|
||||
/// </summary>
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
using System.Web;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Web;
|
||||
using Umbraco.Core;
|
||||
|
||||
namespace Umbraco.Web
|
||||
@@ -11,7 +14,18 @@ namespace Umbraco.Web
|
||||
/// </remarks>
|
||||
internal static class HttpCookieExtensions
|
||||
{
|
||||
internal const string PreviewCookieName = "UMB_PREVIEW";
|
||||
public static string GetPreviewCookieValue(this HttpRequestMessage request)
|
||||
{
|
||||
var cookie = request.Headers.GetCookies(Constants.Web.PreviewCookieName).FirstOrDefault();
|
||||
if (cookie != null)
|
||||
{
|
||||
if (cookie[Constants.Web.PreviewCookieName] != null)
|
||||
{
|
||||
return cookie[Constants.Web.PreviewCookieName].Value;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Does a preview cookie exist ?
|
||||
@@ -20,7 +34,7 @@ namespace Umbraco.Web
|
||||
/// <returns></returns>
|
||||
public static bool HasPreviewCookie(this HttpRequestBase request)
|
||||
{
|
||||
return request.Cookies[PreviewCookieName] != null;
|
||||
return request.Cookies[Constants.Web.PreviewCookieName] != null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections;
|
||||
using System.Configuration;
|
||||
using System.Data;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Security;
|
||||
@@ -10,6 +11,7 @@ using System.Web.UI.HtmlControls;
|
||||
using System.Web.UI.WebControls;
|
||||
using System.Web.UI.WebControls.WebParts;
|
||||
using System.Xml.Linq;
|
||||
using Umbraco.Web;
|
||||
using umbraco.cms.businesslogic.web;
|
||||
using umbraco.presentation.preview;
|
||||
using umbraco.BusinessLogic;
|
||||
@@ -25,14 +27,14 @@ namespace umbraco.presentation.dialogs
|
||||
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
var d = new Document(int.Parse(helper.Request("id")));
|
||||
var pc = new PreviewContent(base.getUser(), Guid.NewGuid(), false);
|
||||
pc.PrepareDocument(base.getUser(), d, true);
|
||||
var d = new Document(Request.GetItemAs<int>("id"));
|
||||
var pc = new PreviewContent(UmbracoUser, Guid.NewGuid(), false);
|
||||
pc.PrepareDocument(UmbracoUser, d, true);
|
||||
pc.SavePreviewSet();
|
||||
docLit.Text = d.Text;
|
||||
changeSetUrl.Text = pc.PreviewsetPath;
|
||||
pc.ActivatePreviewCookie();
|
||||
Response.Redirect("../../" + d.Id.ToString() + ".aspx", true);
|
||||
Response.Redirect("../../" + d.Id.ToString(CultureInfo.InvariantCulture) + ".aspx", true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,8 @@ using Umbraco.Core.IO;
|
||||
|
||||
namespace umbraco.presentation.preview
|
||||
{
|
||||
//TODO : Migrate this to a new API!
|
||||
|
||||
public class PreviewContent
|
||||
{
|
||||
// zb-00004 #29956 : refactor cookies names & handling
|
||||
|
||||
@@ -2,6 +2,7 @@ using System;
|
||||
using System.Reflection;
|
||||
using System.Web;
|
||||
using System.Web.UI;
|
||||
using Umbraco.Core;
|
||||
|
||||
namespace umbraco.BusinessLogic
|
||||
{
|
||||
@@ -348,8 +349,8 @@ namespace umbraco.BusinessLogic
|
||||
* we currently reproduce this by configuring each cookie with a 30d expires, but does
|
||||
* that actually make sense? shouldn't some cookie have _no_ expires?
|
||||
*/
|
||||
static readonly Cookie _preview = new Cookie("UMB_PREVIEW", 30d); // was "PreviewSet"
|
||||
static readonly Cookie _userContext = new Cookie("UMB_UCONTEXT", 30d); // was "UserContext"
|
||||
static readonly Cookie _preview = new Cookie(Constants.Web.PreviewCookieName, 30d); // was "PreviewSet"
|
||||
static readonly Cookie _userContext = new Cookie(Constants.Web.AuthCookieName, 30d); // was "UserContext"
|
||||
static readonly Cookie _member = new Cookie("UMB_MEMBER", 30d); // was "umbracoMember"
|
||||
|
||||
public static Cookie Preview { get { return _preview; } }
|
||||
|
||||
Reference in New Issue
Block a user