Umbraco MVC style routes now implemented.
This commit is contained in:
17
src/Umbraco.Web/Mvc/NotFoundHandler.cs
Normal file
17
src/Umbraco.Web/Mvc/NotFoundHandler.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System.Web;
|
||||
|
||||
namespace Umbraco.Web.Mvc
|
||||
{
|
||||
public class NotFoundHandler : IHttpHandler
|
||||
{
|
||||
public void ProcessRequest(HttpContext context)
|
||||
{
|
||||
context.Response.StatusCode = 404;
|
||||
}
|
||||
|
||||
public bool IsReusable
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
}
|
||||
}
|
||||
25
src/Umbraco.Web/Mvc/UmbracoVirtualNodeByIdRouteHandler.cs
Normal file
25
src/Umbraco.Web/Mvc/UmbracoVirtualNodeByIdRouteHandler.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System.Web.Routing;
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Web.Mvc
|
||||
{
|
||||
public abstract class UmbracoVirtualNodeByIdRouteHandler : UmbracoVirtualNodeRouteHandler
|
||||
{
|
||||
private readonly int _realNodeId;
|
||||
|
||||
protected UmbracoVirtualNodeByIdRouteHandler(int realNodeId)
|
||||
{
|
||||
_realNodeId = realNodeId;
|
||||
}
|
||||
|
||||
protected sealed override IPublishedContent FindContent(RequestContext requestContext, UmbracoContext umbracoContext)
|
||||
{
|
||||
var byId = umbracoContext.ContentCache.GetById(_realNodeId);
|
||||
if (byId == null) return null;
|
||||
|
||||
return FindContent(requestContext, umbracoContext, byId);
|
||||
}
|
||||
|
||||
protected abstract IPublishedContent FindContent(RequestContext requestContext, UmbracoContext umbracoContext, IPublishedContent baseContent);
|
||||
}
|
||||
}
|
||||
47
src/Umbraco.Web/Mvc/UmbracoVirtualNodeRouteHandler.cs
Normal file
47
src/Umbraco.Web/Mvc/UmbracoVirtualNodeRouteHandler.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Routing;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Web.Models;
|
||||
using Umbraco.Web.Routing;
|
||||
|
||||
namespace Umbraco.Web.Mvc
|
||||
{
|
||||
public abstract class UmbracoVirtualNodeRouteHandler : IRouteHandler
|
||||
{
|
||||
public IHttpHandler GetHttpHandler(RequestContext requestContext)
|
||||
{
|
||||
var umbracoContext = UmbracoContext.Current;
|
||||
|
||||
var found = FindContent(requestContext, umbracoContext);
|
||||
if (found == null) return new NotFoundHandler();
|
||||
|
||||
umbracoContext.PublishedContentRequest = new PublishedContentRequest(
|
||||
umbracoContext.CleanedUmbracoUrl, umbracoContext.RoutingContext)
|
||||
{
|
||||
PublishedContent = found
|
||||
};
|
||||
|
||||
//allows inheritors to change the pcr
|
||||
PreparePublishedContentRequest(umbracoContext.PublishedContentRequest);
|
||||
|
||||
//create the render model
|
||||
var renderModel = new RenderModel(umbracoContext.PublishedContentRequest.PublishedContent, umbracoContext.PublishedContentRequest.Culture);
|
||||
|
||||
//assigns the required tokens to the request
|
||||
requestContext.RouteData.DataTokens.Add("umbraco", renderModel);
|
||||
requestContext.RouteData.DataTokens.Add("umbraco-doc-request", umbracoContext.PublishedContentRequest);
|
||||
requestContext.RouteData.DataTokens.Add("umbraco-context", umbracoContext);
|
||||
|
||||
umbracoContext.PublishedContentRequest.ConfigureRequest();
|
||||
|
||||
return new MvcHandler(requestContext);
|
||||
}
|
||||
|
||||
protected abstract IPublishedContent FindContent(RequestContext requestContext, UmbracoContext umbracoContext);
|
||||
|
||||
protected virtual void PreparePublishedContentRequest(PublishedContentRequest publishedContentRequest)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -362,8 +362,10 @@
|
||||
<Compile Include="Models\PostRedirectModel.cs" />
|
||||
<Compile Include="Models\PublishedProperty.cs" />
|
||||
<Compile Include="Mvc\ActionExecutedEventArgs.cs" />
|
||||
<Compile Include="Mvc\NotFoundHandler.cs" />
|
||||
<Compile Include="Mvc\PreRenderViewActionFilterAttribute.cs" />
|
||||
<Compile Include="Mvc\RedirectToUmbracoUrlResult.cs" />
|
||||
<Compile Include="Mvc\UmbracoVirtualNodeByIdRouteHandler.cs" />
|
||||
<Compile Include="PropertyEditors\TagsDataController.cs" />
|
||||
<Compile Include="PublishedCache\MemberPublishedContent.cs" />
|
||||
<Compile Include="PublishedCache\RawValueProperty.cs" />
|
||||
@@ -471,6 +473,7 @@
|
||||
<Compile Include="PropertyEditors\PropertyValueEditorWrapper.cs" />
|
||||
<Compile Include="PublishedContentQuery.cs" />
|
||||
<Compile Include="ImageCropperTemplateExtensions.cs" />
|
||||
<Compile Include="Mvc\UmbracoVirtualNodeRouteHandler.cs" />
|
||||
<Compile Include="Routing\UrlProviderExtensions.cs" />
|
||||
<Compile Include="Strategies\Migrations\ClearCsrfCookiesAfterUpgrade.cs" />
|
||||
<Compile Include="Strategies\Migrations\ClearMediaXmlCacheForDeletedItemsAfterUpgrade.cs" />
|
||||
|
||||
Reference in New Issue
Block a user