diff --git a/.hgignore b/.hgignore index 6f19e4c261..fde466ac03 100644 --- a/.hgignore +++ b/.hgignore @@ -45,3 +45,4 @@ src/Umbraco.Tests/config/applications.config src/Umbraco.Tests/config/trees.config src/Umbraco.Web.UI/web.config src/Umbraco.Tests/config/404handlers.config +src/Umbraco.Web.UI/Views/* diff --git a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj index 1dfdb84097..76be138a12 100644 --- a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj +++ b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj @@ -5,7 +5,7 @@ 9.0.30729 2.0 {4C4C194C-B5E4-4991-8F87-4373E24CC19F} - {349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} + {E53F8FEA-EAE0-44A6-8774-FFD645390401};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} Debug AnyCPU @@ -1306,6 +1306,7 @@ applications.config Designer + Web.Template.config Designer diff --git a/src/Umbraco.Web/Mvc/RenderMvcController.cs b/src/Umbraco.Web/Mvc/RenderMvcController.cs index 0da24d14a6..4eb67f4508 100644 --- a/src/Umbraco.Web/Mvc/RenderMvcController.cs +++ b/src/Umbraco.Web/Mvc/RenderMvcController.cs @@ -50,7 +50,7 @@ namespace Umbraco.Web.Mvc Path.Combine(Server.MapPath(Constants.ViewLocation), template + ".cshtml"))) { LogHelper.Warn("No physical template file was found for template " + template); - return Content("No template"); + return Content(""); } return View(template, model); diff --git a/src/Umbraco.Web/Mvc/RenderRouteHandler.cs b/src/Umbraco.Web/Mvc/RenderRouteHandler.cs index 5537cefc28..28198aedd7 100644 --- a/src/Umbraco.Web/Mvc/RenderRouteHandler.cs +++ b/src/Umbraco.Web/Mvc/RenderRouteHandler.cs @@ -1,3 +1,4 @@ +using System; using System.Web; using System.Web.Mvc; using System.Web.Routing; @@ -30,11 +31,14 @@ namespace Umbraco.Web.Mvc { if (UmbracoContext.Current == null) { - return new MvcHandler(requestContext); + throw new NullReferenceException("There is not current UmbracoContext, it must be initialized before the RenderRouteHandler executes"); + } + var docRequest = UmbracoContext.Current.DocumentRequest; + if (docRequest == null) + { + throw new NullReferenceException("There is not current DocumentRequest, it must be initialized before the RenderRouteHandler executes"); } - var docRequest = UmbracoContext.Current.DocumentRequest; - var renderModel = new RenderModel() { CurrentNode = docRequest.Node @@ -43,6 +47,7 @@ namespace Umbraco.Web.Mvc //put essential data into the data tokens, the 'umbraco' key is required to be there for the view engine requestContext.RouteData.DataTokens.Add("umbraco", renderModel); //required for the RenderModelBinder requestContext.RouteData.DataTokens.Add("umbraco-doc-request", docRequest); //required for RenderMvcController + requestContext.RouteData.DataTokens.Add("umbraco-context", UmbracoContext.Current); //required for RenderViewPage return GetHandlerForRoute(requestContext, docRequest); diff --git a/src/Umbraco.Web/Mvc/RenderViewPage.cs b/src/Umbraco.Web/Mvc/RenderViewPage.cs index 8ced37ad1f..0a67b12c56 100644 --- a/src/Umbraco.Web/Mvc/RenderViewPage.cs +++ b/src/Umbraco.Web/Mvc/RenderViewPage.cs @@ -1,4 +1,5 @@ using System.Web.Mvc; +using Umbraco.Web.Routing; namespace Umbraco.Web.Mvc { @@ -7,25 +8,30 @@ namespace Umbraco.Web.Mvc /// public abstract class RenderViewPage : WebViewPage { - //protected RenderViewPage() - //{ + protected RenderViewPage() + { - //} + } - //protected override void InitializePage() - //{ - // //set the model to the current node if it is not set, this is generally not the case - // if (Model != null) - // { - // //this.ViewData.Model = Model; - // var backingItem = new DynamicBackingItem(Model.CurrentNode); - // var dynamicNode = new DynamicNode(backingItem); - // CurrentPage = dynamicNode; - // } - //} + protected override void InitializePage() + { + //set the model to the current node if it is not set, this is generally not the case + if (Model != null) + { + ////this.ViewData.Model = Model; + //var backingItem = new DynamicBackingItem(Model.CurrentNode); + //var dynamicNode = new DynamicNode(backingItem); + //CurrentPage = dynamicNode; + } + DocumentRequest = (DocumentRequest)ViewContext.RouteData.DataTokens.GetRequiredObject("umbraco-doc-request"); + UmbracoContext = (UmbracoContext)ViewContext.RouteData.DataTokens.GetRequiredObject("umbraco-context"); + } + public UmbracoContext UmbracoContext { get; private set; } - //public dynamic CurrentPage { get; private set; } + internal DocumentRequest DocumentRequest { get; private set; } + + public dynamic CurrentPage { get; private set; } //private ICultureDictionary _cultureDictionary; //public string GetDictionary(string key) diff --git a/src/Umbraco.Web/RouteValueDictionaryExtensions.cs b/src/Umbraco.Web/RouteValueDictionaryExtensions.cs new file mode 100644 index 0000000000..5989dbe295 --- /dev/null +++ b/src/Umbraco.Web/RouteValueDictionaryExtensions.cs @@ -0,0 +1,41 @@ +using System; +using System.Linq; +using System.Web.Mvc; +using System.Web.Routing; + +namespace Umbraco.Web +{ + internal static class RouteValueDictionaryExtensions + { + + /// + /// Converts a route value dictionary to a form collection + /// + /// + /// + public static FormCollection ToFormCollection(this RouteValueDictionary items) + { + var formCollection = new FormCollection(); + foreach (var i in items) + { + formCollection.Add(i.Key, i.Value != null ? i.Value.ToString() : null); + } + return formCollection; + } + + /// + /// Returns the value of a mandatory item in the route items + /// + /// + /// + /// + public static object GetRequiredObject(this RouteValueDictionary items, string key) + { + if (key == null) throw new ArgumentNullException("key"); + if (!items.Keys.Contains(key)) + throw new ArgumentNullException("The " + key + " parameter was not found but is required"); + return items[key]; + } + + } +} \ No newline at end of file diff --git a/src/Umbraco.Web/Routing/LookupByNiceUrl.cs b/src/Umbraco.Web/Routing/LookupByNiceUrl.cs index 588244665c..9cdfd5670f 100644 --- a/src/Umbraco.Web/Routing/LookupByNiceUrl.cs +++ b/src/Umbraco.Web/Routing/LookupByNiceUrl.cs @@ -31,7 +31,7 @@ namespace Umbraco.Web.Routing //TODO: When this is not IIS 7, this does not work for the root '/' request since it comes through as default.aspx!! // this needs fixing. - //format the path + //format the path, thsi needs fixing when pre-IIS7 route = route.Replace(".aspx", ""); var node = LookupDocumentNode(docreq, route); diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 5eb59e8e94..5a425a07d1 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -253,6 +253,7 @@ + diff --git a/src/Umbraco.Web/UriUtility.cs b/src/Umbraco.Web/UriUtility.cs index abd3d0e910..488a6f2df6 100644 --- a/src/Umbraco.Web/UriUtility.cs +++ b/src/Umbraco.Web/UriUtility.cs @@ -62,10 +62,19 @@ namespace Umbraco.Web return uri.Rewrite(path); } + /// + /// Converts a Uri to a path based URI that is lower cased + /// + /// + /// public static Uri UriToUmbraco(Uri uri) { var path = uri.GetSafeAbsolutePath(); + //we need to check if the path is /default.aspx because this will occur when using a + //web server pre IIS 7 when requesting the root document + //if this is the case we need to change it to '/' + path = path.ToLower(); if (path != "/") path = path.TrimEnd('/'); diff --git a/src/Umbraco.Web/WebBootManager.cs b/src/Umbraco.Web/WebBootManager.cs index fb3dc7ec0b..3376a76ea2 100644 --- a/src/Umbraco.Web/WebBootManager.cs +++ b/src/Umbraco.Web/WebBootManager.cs @@ -10,7 +10,6 @@ using umbraco.businesslogic; namespace Umbraco.Web { - /// /// A bootstrapper for the Umbraco application which initializes all objects including the Web portion of the application /// diff --git a/src/Umbraco.Web/umbraco.presentation/default.aspx.cs b/src/Umbraco.Web/umbraco.presentation/default.aspx.cs index 17010eb739..d09a30c642 100644 --- a/src/Umbraco.Web/umbraco.presentation/default.aspx.cs +++ b/src/Umbraco.Web/umbraco.presentation/default.aspx.cs @@ -212,7 +212,8 @@ namespace umbraco } //TODO: This should be removed, we should be handling all 404 stuff in the module and executing the - // DocumentNotFoundHttpHandler instead. + // DocumentNotFoundHttpHandler instead but we need to fix the above routing concerns so that this all + // takes place in the Module. void RenderNotFound() { Context.Response.StatusCode = 404;