U4-7914 - add PublishedContentRequest.Preparing event

This commit is contained in:
Stephan
2016-02-18 11:36:48 +01:00
parent 51ed441b85
commit 9293008b94
2 changed files with 42 additions and 3 deletions

View File

@@ -21,6 +21,15 @@ namespace Umbraco.Web.Routing
public class PublishedContentRequest
{
private bool _readonly;
private bool _readonlyUri;
/// <summary>
/// Triggers before the published content request is prepared.
/// </summary>
/// <remarks>When the event triggers, no preparation has been done. It is still possible to
/// modify the request's Uri property, for example to restore its original, public-facing value
/// that might have been modified by an in-between equipement such as a load-balancer.</remarks>
public static event EventHandler<EventArgs> Preparing;
/// <summary>
/// Triggers once the published content request has been prepared, but before it is processed.
@@ -35,6 +44,10 @@ namespace Umbraco.Web.Routing
// the content request is just a data holder
private readonly PublishedContentRequestEngine _engine;
// the cleaned up uri
// the cleaned up Uri has no virtual directory, no trailing slash, no .aspx extension, etc.
private Uri _uri;
/// <summary>
/// Initializes a new instance of the <see cref="PublishedContentRequest"/> class with a specific Uri and routing context.
/// </summary>
@@ -102,13 +115,23 @@ namespace Umbraco.Web.Routing
_readonly = __readonly;
}
/// <summary>
/// Triggers the Preparing event.
/// </summary>
internal void OnPreparing()
{
var handler = Preparing;
if (handler != null) handler(this, EventArgs.Empty);
_readonlyUri = true;
}
/// <summary>
/// Triggers the Prepared event.
/// </summary>
internal void OnPrepared()
{
if (Prepared != null)
Prepared(this, EventArgs.Empty);
var handler = Prepared;
if (handler != null) handler(this, EventArgs.Empty);
if (HasPublishedContent == false)
Is404 = true; // safety
@@ -120,7 +143,18 @@ 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 { get; private set; }
public Uri Uri {
get
{
return _uri;
}
set
{
if (_readonlyUri)
throw new InvalidOperationException("Cannot modify Uri after Preparing has triggered.");
_uri = value;
}
}
private void EnsureWriteable()
{

View File

@@ -84,6 +84,11 @@ namespace Umbraco.Web.Routing
// so that they point to a non-existing page eg /redirect-404.aspx
// TODO: SD: We need more information on this for when we release 4.10.0 as I'm not sure what this means.
// trigger the Preparing event - at that point anything can still be changed
// the idea is that it is possible to change the uri
//
_pcr.OnPreparing();
//find domain
FindDomain();