diff --git a/src/Umbraco.Web/Routing/PublishedContentRequest.cs b/src/Umbraco.Web/Routing/PublishedContentRequest.cs
index 02ffc475d3..1ed0cf8150 100644
--- a/src/Umbraco.Web/Routing/PublishedContentRequest.cs
+++ b/src/Umbraco.Web/Routing/PublishedContentRequest.cs
@@ -21,6 +21,15 @@ namespace Umbraco.Web.Routing
public class PublishedContentRequest
{
private bool _readonly;
+ private bool _readonlyUri;
+
+ ///
+ /// Triggers before the published content request is prepared.
+ ///
+ /// 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.
+ public static event EventHandler Preparing;
///
/// 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;
+
///
/// Initializes a new instance of the class with a specific Uri and routing context.
///
@@ -102,13 +115,23 @@ namespace Umbraco.Web.Routing
_readonly = __readonly;
}
+ ///
+ /// Triggers the Preparing event.
+ ///
+ internal void OnPreparing()
+ {
+ var handler = Preparing;
+ if (handler != null) handler(this, EventArgs.Empty);
+ _readonlyUri = true;
+ }
+
///
/// Triggers the Prepared event.
///
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.
///
/// The cleaned up Uri has no virtual directory, no trailing slash, no .aspx extension, etc.
- 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()
{
diff --git a/src/Umbraco.Web/Routing/PublishedContentRequestEngine.cs b/src/Umbraco.Web/Routing/PublishedContentRequestEngine.cs
index 2e075d8ed1..03a50a4b99 100644
--- a/src/Umbraco.Web/Routing/PublishedContentRequestEngine.cs
+++ b/src/Umbraco.Web/Routing/PublishedContentRequestEngine.cs
@@ -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();