U4-8361 301 Url Tracking
Adds the ability to add certain headers to a PublishedContentRequest - these are internal for now until we're sure we want to expose them Adds response headers to tell browsers not to cache the 301 redirects so people can easily change their mind later
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
using Umbraco.Core;
|
||||
using System.Collections.Generic;
|
||||
using System.Web;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Logging;
|
||||
|
||||
namespace Umbraco.Web.Routing
|
||||
@@ -27,6 +29,14 @@ namespace Umbraco.Web.Routing
|
||||
var service = contentRequest.RoutingContext.UmbracoContext.Application.Services.RedirectUrlService;
|
||||
var redirectUrl = service.GetMostRecentRedirectUrl(route);
|
||||
|
||||
// From: http://stackoverflow.com/a/22468386/5018
|
||||
// See http://issues.umbraco.org/issue/U4-8361#comment=67-30532
|
||||
// Setting automatic 301 redirects to not be cached because browsers cache these very aggressively which then leads
|
||||
// to problems if you rename a page back to it's original name or create a new page with the original name
|
||||
contentRequest.Cacheability = HttpCacheability.NoCache;
|
||||
contentRequest.CacheExtensions = new List<string> { "no-store, must-revalidate" };
|
||||
contentRequest.Headers = new Dictionary<string, string> { { "Pragma", "no-cache" }, { "Expires", "0" } };
|
||||
|
||||
if (redirectUrl == null)
|
||||
{
|
||||
LogHelper.Debug<ContentFinderByRedirectUrl>("No match for route: \"{0}\".", () => route);
|
||||
|
||||
@@ -2,6 +2,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.Web;
|
||||
using System.Web.Security;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration;
|
||||
@@ -143,7 +144,8 @@ namespace Umbraco.Web.Routing
|
||||
/// Gets or sets the cleaned up Uri used for routing.
|
||||
/// </summary>
|
||||
/// <remarks>The cleaned up Uri has no virtual directory, no trailing slash, no .aspx extension, etc.</remarks>
|
||||
public Uri Uri {
|
||||
public Uri Uri
|
||||
{
|
||||
get
|
||||
{
|
||||
return _uri;
|
||||
@@ -583,5 +585,38 @@ namespace Umbraco.Web.Routing
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the <c>System.Web.HttpCacheability</c>
|
||||
/// </summary>
|
||||
/// <remarks>Is set to <c>System.Web.HttpCacheability.Private</c> by default, which is the ASP.NET default.</remarks>
|
||||
private HttpCacheability _cacheability = HttpCacheability.Private;
|
||||
internal HttpCacheability Cacheability
|
||||
{
|
||||
get { return _cacheability; }
|
||||
set { _cacheability = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a list of Extensions to append to the Response.Cache object
|
||||
/// </summary>
|
||||
private List<string> _cacheExtensions = new List<string>();
|
||||
internal List<string> CacheExtensions
|
||||
{
|
||||
get { return _cacheExtensions; }
|
||||
set { _cacheExtensions = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a dictionary of Headers to append to the Response object
|
||||
/// </summary>
|
||||
private Dictionary<string, string> _headers = new Dictionary<string, string>();
|
||||
internal Dictionary<string, string> Headers
|
||||
{
|
||||
get { return _headers; }
|
||||
set { _headers = value; }
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -324,6 +324,14 @@ namespace Umbraco.Web
|
||||
() => pcr.IsRedirect ? (pcr.IsRedirectPermanent ? "permanent" : "redirect") : "none",
|
||||
() => pcr.Is404 ? "true" : "false", () => pcr.ResponseStatusCode);
|
||||
|
||||
response.Cache.SetCacheability(pcr.Cacheability);
|
||||
|
||||
foreach (var cacheExtension in pcr.CacheExtensions)
|
||||
response.Cache.AppendCacheExtension(cacheExtension);
|
||||
|
||||
foreach (var header in pcr.Headers)
|
||||
response.Cache.AppendCacheExtension(string.Format("{0}, {1}", header.Key, header.Value));
|
||||
|
||||
if (pcr.IsRedirect)
|
||||
{
|
||||
if (pcr.IsRedirectPermanent)
|
||||
|
||||
Reference in New Issue
Block a user