Removes a ton of old code

This commit is contained in:
Shannon
2021-02-03 15:59:50 +11:00
parent 0c26a82489
commit 57f3de7652
28 changed files with 6 additions and 1733 deletions

View File

@@ -1,4 +1,4 @@
using System;
using System;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Umbraco.Core;
@@ -151,28 +151,7 @@ namespace Umbraco.Web.Composing
#endregion
#region Web Constants
// these are different - not 'resolving' anything, and nothing that could be managed
// by the container - just registering some sort of application-wide constants or
// settings - but they fit in Current nicely too
private static Type _defaultRenderMvcControllerType;
// internal - can only be accessed through Composition at compose time
internal static Type DefaultRenderMvcControllerType
{
get => _defaultRenderMvcControllerType;
set
{
if (value.Implements<IRenderController>() == false)
throw new ArgumentException($"Type {value.FullName} does not implement {typeof(IRenderController).FullName}.", nameof(value));
_defaultRenderMvcControllerType = value;
}
}
#endregion
#region Core Getters
// proxy Core for convenience

View File

@@ -1,137 +0,0 @@
using System;
using System.Collections.Generic;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Routing;
using System.Web.SessionState;
using Umbraco.Core;
using Umbraco.Core.Configuration;
using Umbraco.Core.Configuration.Models;
using Umbraco.Core.Hosting;
using Umbraco.Web.WebApi;
namespace Umbraco.Web.Mvc
{
internal static class AreaRegistrationExtensions
{
/// <summary>
/// Creates a custom individual route for the specified controller plugin. Individual routes
/// are required by controller plugins to map to a unique URL based on ID.
/// </summary>
/// <param name="hostingEnvironment"></param>
/// <param name="controllerName"></param>
/// <param name="controllerType"></param>
/// <param name="routes">An existing route collection</param>
/// <param name="controllerSuffixName">
/// The suffix name that the controller name must end in before the "Controller" string for example:
/// ContentTreeController has a controllerSuffixName of "Tree", this is used for route constraints.
/// </param>
/// <param name="defaultAction"></param>
/// <param name="defaultId"></param>
/// <param name="area"></param>
/// <param name="umbracoTokenValue">The DataToken value to set for the 'umbraco' key, this defaults to 'backoffice' </param>
/// <param name="routeTokens">By default this value is just {action}/{id} but can be modified for things like web api routes</param>
/// <param name="isMvc">Default is true for MVC, otherwise false for WebAPI</param>
/// <param name="areaPathPrefix">
/// If specified will add this string to the path between the umbraco path and the area path name, for example:
/// /umbraco/CUSTOMPATHPREFIX/areaname
/// if not specified, will just route like:
/// /umbraco/areaname
/// </param>
/// <param name="globalSettings"></param>
/// <remarks>
/// </remarks>
internal static Route RouteControllerPlugin(this AreaRegistration area,
GlobalSettings globalSettings, IHostingEnvironment hostingEnvironment,
string controllerName, Type controllerType, RouteCollection routes,
string controllerSuffixName, string defaultAction, object defaultId,
string umbracoTokenValue = "backoffice",
string routeTokens = "{action}/{id}",
bool isMvc = true,
string areaPathPrefix = "")
{
if (controllerName == null) throw new ArgumentNullException(nameof(controllerName));
if (string.IsNullOrEmpty(controllerName)) throw new ArgumentException("Value can't be empty.", nameof(controllerName));
if (controllerSuffixName == null) throw new ArgumentNullException(nameof(controllerSuffixName));
if (controllerType == null) throw new ArgumentNullException(nameof(controllerType));
if (routes == null) throw new ArgumentNullException(nameof(routes));
if (defaultId == null) throw new ArgumentNullException(nameof(defaultId));
var umbracoArea = globalSettings.GetUmbracoMvcArea(hostingEnvironment);
//routes are explicitly named with controller names and IDs
var url = umbracoArea + "/" +
(areaPathPrefix.IsNullOrWhiteSpace() ? "" : areaPathPrefix + "/") +
area.AreaName + "/" + controllerName + "/" + routeTokens;
Route controllerPluginRoute;
//var meta = PluginController.GetMetadata(controllerType);
if (isMvc)
{
//create a new route with custom name, specified URL, and the namespace of the controller plugin
controllerPluginRoute = routes.MapRoute(
//name
string.Format("umbraco-{0}-{1}", area.AreaName, controllerName),
//URL format
url,
//set the namespace of the controller to match
new[] {controllerType.Namespace});
//set defaults
controllerPluginRoute.Defaults = new RouteValueDictionary(
new Dictionary<string, object>
{
{"controller", controllerName},
{"action", defaultAction},
{"id", defaultId}
});
}
else
{
controllerPluginRoute = routes.MapHttpRoute(
//name
string.Format("umbraco-{0}-{1}-{2}", "api", area.AreaName, controllerName),
//URL format
url,
new {controller = controllerName, id = defaultId});
//web api routes don't set the data tokens object
if (controllerPluginRoute.DataTokens == null)
{
controllerPluginRoute.DataTokens = new RouteValueDictionary();
}
//look in this namespace to create the controller
controllerPluginRoute.DataTokens.Add("Namespaces", new[] {controllerType.Namespace});
//Special case! Check if the controller type implements IRequiresSessionState and if so use our
//custom webapi session handler
if (typeof(IRequiresSessionState).IsAssignableFrom(controllerType))
{
controllerPluginRoute.RouteHandler = new SessionHttpControllerRouteHandler();
}
}
//Don't look anywhere else except this namespace!
controllerPluginRoute.DataTokens.Add("UseNamespaceFallback", false);
//constraints: only match controllers ending with 'controllerSuffixName' and only match this controller's ID for this route
if (controllerSuffixName.IsNullOrWhiteSpace() == false)
{
controllerPluginRoute.Constraints = new RouteValueDictionary(
new Dictionary<string, object>
{
{"controller", @"(\w+)" + controllerSuffixName}
});
}
//match this area
controllerPluginRoute.DataTokens.Add("area", area.AreaName);
// TODO: No longer needed, remove
//controllerPluginRoute.DataTokens.Add(Core.Constants.Web.UmbracoDataToken, umbracoTokenValue); //ensure the umbraco token is set
return controllerPluginRoute;
}
}
}

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.IO;
using System.Threading;
using System.Web.Mvc;
@@ -43,164 +43,5 @@ namespace Umbraco.Web.Mvc
return GetControllerName(typeof(T));
}
/// <summary>
/// This is generally used for proxying to a ChildAction which requires a ViewContext to be setup
/// but since the View isn't actually rendered the IView object is null, however the rest of the
/// properties are filled in.
/// </summary>
/// <param name="controller"></param>
/// <returns></returns>
internal static ViewContext CreateEmptyViewContext(this ControllerBase controller)
{
return new ViewContext
{
Controller = controller,
HttpContext = controller.ControllerContext.HttpContext,
RequestContext = controller.ControllerContext.RequestContext,
RouteData = controller.ControllerContext.RouteData,
TempData = controller.TempData,
ViewData = controller.ViewData
};
}
/// <summary>
/// Returns the string output from a ViewResultBase object
/// </summary>
/// <param name="controller"></param>
/// <param name="viewResult"></param>
/// <returns></returns>
internal static string RenderViewResultAsString(this ControllerBase controller, ViewResultBase viewResult)
{
using (var sw = new StringWriter())
{
controller.EnsureViewObjectDataOnResult(viewResult);
var viewContext = new ViewContext(controller.ControllerContext, viewResult.View, viewResult.ViewData, viewResult.TempData, sw);
viewResult.View.Render(viewContext, sw);
foreach (var v in viewResult.ViewEngineCollection)
{
v.ReleaseView(controller.ControllerContext, viewResult.View);
}
return sw.ToString().Trim();
}
}
/// <summary>
/// Renders the partial view to string.
/// </summary>
/// <param name="controller">The controller context.</param>
/// <param name="viewName">Name of the view.</param>
/// <param name="model">The model.</param>
/// <param name="isPartial">true if it is a Partial view, otherwise false for a normal view </param>
/// <returns></returns>
internal static string RenderViewToString(this ControllerBase controller, string viewName, object model, bool isPartial = false)
{
if (controller.ControllerContext == null)
throw new ArgumentException("The controller must have an assigned ControllerContext to execute this method.");
controller.ViewData.Model = model;
using (var sw = new StringWriter())
{
var viewResult = isPartial == false
? ViewEngines.Engines.FindView(controller.ControllerContext, viewName, null)
: ViewEngines.Engines.FindPartialView(controller.ControllerContext, viewName);
if (viewResult.View == null)
throw new InvalidOperationException("No view could be found by name " + viewName);
var viewContext = new ViewContext(controller.ControllerContext, viewResult.View, controller.ViewData, controller.TempData, sw);
viewResult.View.Render(viewContext, sw);
viewResult.ViewEngine.ReleaseView(controller.ControllerContext, viewResult.View);
return sw.GetStringBuilder().ToString();
}
}
/// <summary>
/// Renders the partial view to string.
/// </summary>
/// <param name="requestContext">The request context.</param>
/// <param name="viewData"></param>
/// <param name="tempData"></param>
/// <param name="viewName">Name of the view.</param>
/// <param name="model">The model.</param>
/// <param name="isPartial">true if it is a Partial view, otherwise false for a normal view </param>
/// <returns></returns>
internal static string RenderViewToString(
this RequestContext requestContext,
ViewDataDictionary viewData,
TempDataDictionary tempData,
string viewName, object model, bool isPartial = false)
{
if (requestContext == null) throw new ArgumentNullException("requestContext");
if (viewData == null) throw new ArgumentNullException("viewData");
if (tempData == null) throw new ArgumentNullException("tempData");
var routeData = requestContext.RouteData;
if (routeData.Values.ContainsKey("controller") == false)
routeData.Values.Add("controller", "Fake");
viewData.Model = model;
var controllerContext = new ControllerContext(
requestContext.HttpContext, routeData,
new FakeController
{
ViewData = viewData
});
using (var sw = new StringWriter())
{
var viewResult = isPartial == false
? ViewEngines.Engines.FindView(controllerContext, viewName, null)
: ViewEngines.Engines.FindPartialView(controllerContext, viewName);
if (viewResult.View == null)
throw new InvalidOperationException("No view could be found by name " + viewName);
var viewContext = new ViewContext(controllerContext, viewResult.View, viewData, tempData, sw);
viewResult.View.Render(viewContext, sw);
viewResult.ViewEngine.ReleaseView(controllerContext, viewResult.View);
return sw.GetStringBuilder().ToString();
}
}
private class FakeController : ControllerBase { protected override void ExecuteCore() { } }
/// <summary>
/// Normally in MVC the way that the View object gets assigned to the result is to Execute the ViewResult, this however
/// will write to the Response output stream which isn't what we want. Instead, this method will use the same logic inside
/// of MVC to assign the View object to the result but without executing it.
/// This is only relevant for view results of PartialViewResult or ViewResult.
/// </summary>
/// <param name="result"></param>
/// <param name="controller"></param>
private static void EnsureViewObjectDataOnResult(this ControllerBase controller, ViewResultBase result)
{
if (result.View != null) return;
if (string.IsNullOrEmpty(result.ViewName))
result.ViewName = controller.ControllerContext.RouteData.GetRequiredString("action");
if (result.View != null) return;
if (result is PartialViewResult)
{
var viewEngineResult = ViewEngines.Engines.FindPartialView(controller.ControllerContext, result.ViewName);
if (viewEngineResult.View == null)
{
throw new InvalidOperationException("Could not find the view " + result.ViewName + ", the following locations were searched: " + Environment.NewLine + string.Join(Environment.NewLine, viewEngineResult.SearchedLocations));
}
result.View = viewEngineResult.View;
}
else if (result is ViewResult)
{
var vr = (ViewResult)result;
var viewEngineResult = ViewEngines.Engines.FindView(controller.ControllerContext, vr.ViewName, vr.MasterName);
if (viewEngineResult.View == null)
{
throw new InvalidOperationException("Could not find the view " + vr.ViewName + ", the following locations were searched: " + Environment.NewLine + string.Join(Environment.NewLine, viewEngineResult.SearchedLocations));
}
result.View = viewEngineResult.View;
}
}
}
}

View File

@@ -1,36 +0,0 @@
using System;
using System.Web.Mvc;
using System.Web.Routing;
namespace Umbraco.Web.Mvc
{
internal static class ControllerFactoryExtensions
{
/// <summary>
/// Gets a controller type by the name
/// </summary>
/// <param name="factory"></param>
/// <param name="requestContext"></param>
/// <param name="controllerName"></param>
/// <returns></returns>
/// <remarks>
/// This is related to issue: http://issues.umbraco.org/issue/U4-1726. We already have a method called GetControllerTypeInternal on our MasterControllerFactory,
/// however, we cannot always guarantee that the usage of this will be a MasterControllerFactory like during unit tests. So we needed to create
/// this extension method to do the checks instead.
/// </remarks>
internal static Type GetControllerTypeInternal(this IControllerFactory factory, RequestContext requestContext, string controllerName)
{
//TODO Reintroduce for netcore
// if (factory is MasterControllerFactory controllerFactory)
// return controllerFactory.GetControllerTypeInternal(requestContext, controllerName);
//we have no choice but to instantiate the controller
var instance = factory.CreateController(requestContext, controllerName);
var controllerType = instance?.GetType();
factory.ReleaseController(instance);
return controllerType;
}
}
}

View File

@@ -1,46 +0,0 @@
using System;
using System.Runtime.Serialization;
using System.Web;
namespace Umbraco.Web.Mvc
{
/// <summary>
/// Exception that occurs when an Umbraco form route string is invalid
/// </summary>
/// <seealso cref="System.Web.HttpException" />
[Serializable]
public sealed class HttpUmbracoFormRouteStringException : HttpException
{
/// <summary>
/// Initializes a new instance of the <see cref="HttpUmbracoFormRouteStringException" /> class.
/// </summary>
public HttpUmbracoFormRouteStringException()
{ }
/// <summary>
/// Initializes a new instance of the <see cref="HttpUmbracoFormRouteStringException" /> class.
/// </summary>
/// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo" /> that holds the serialized object data about the exception being thrown.</param>
/// <param name="context">The <see cref="T:System.Runtime.Serialization.StreamingContext" /> that holds the contextual information about the source or destination.</param>
private HttpUmbracoFormRouteStringException(SerializationInfo info, StreamingContext context)
: base(info, context)
{ }
/// <summary>
/// Initializes a new instance of the <see cref="HttpUmbracoFormRouteStringException" /> class.
/// </summary>
/// <param name="message">The error message displayed to the client when the exception is thrown.</param>
public HttpUmbracoFormRouteStringException(string message)
: base(message)
{ }
/// <summary>
/// Initializes a new instance of the <see cref="HttpUmbracoFormRouteStringException" /> class.
/// </summary>
/// <param name="message">The error message displayed to the client when the exception is thrown.</param>
/// <param name="innerException">The <see cref="P:System.Exception.InnerException" />, if any, that threw the current exception.</param>
public HttpUmbracoFormRouteStringException(string message, Exception innerException)
: base(message, innerException)
{ }
}
}

View File

@@ -1,8 +0,0 @@
namespace Umbraco.Web.Mvc
{
//Migrated to .NET Core
public interface IRenderController
{
}
}

View File

@@ -1,8 +0,0 @@
namespace Umbraco.Web.Mvc
{
//Migrated to .NET Core
public interface IRenderMvcController : IRenderController
{
}
}

View File

@@ -1,20 +0,0 @@
using System.Web.Mvc;
namespace Umbraco.Web.Mvc
{
/// <summary>
/// Used to ensure that actions with duplicate names that are not child actions don't get executed when
/// we are Posting and not redirecting.
/// </summary>
/// <remarks>
/// See issue: http://issues.umbraco.org/issue/U4-1819
/// </remarks>
public class NotChildAction : ActionMethodSelectorAttribute
{
public override bool IsValidForRequest(ControllerContext controllerContext, System.Reflection.MethodInfo methodInfo)
{
var isChildAction = controllerContext.IsChildAction;
return !isChildAction;
}
}
}

View File

@@ -1,17 +0,0 @@
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; }
}
}
}

View File

@@ -1,12 +0,0 @@
using System;
namespace Umbraco.Web.Mvc
{
/// <summary>
/// Represents the data required to proxy a request to a surface controller for posted data
/// </summary>
internal class PostedDataProxyInfo : RouteDefinition
{
public string Area { get; set; }
}
}

View File

@@ -1,29 +0,0 @@
using System.IO;
using System.Web.Mvc;
using Umbraco.Web.Composing;
namespace Umbraco.Web.Mvc
{
public class ProfilingView : IView
{
private readonly IView _inner;
private readonly string _name;
private readonly string _viewPath;
public ProfilingView(IView inner)
{
_inner = inner;
_name = inner.GetType().Name;
var razorView = inner as RazorView;
_viewPath = razorView != null ? razorView.ViewPath : "Unknown";
}
public void Render(ViewContext viewContext, TextWriter writer)
{
using (Current.Profiler.Step(string.Format("{0}.Render: {1}", _name, _viewPath)))
{
_inner.Render(viewContext, writer);
}
}
}
}

View File

@@ -1,58 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Umbraco.Core;
namespace Umbraco.Web.Mvc
{
/// <summary>
/// Allows an Action to execute with an arbitrary number of QueryStrings
/// </summary>
/// <remarks>
/// Just like you can POST an arbitrary number of parameters to an Action, you can't GET an arbitrary number
/// but this will allow you to do it
///
/// http://stackoverflow.com/questions/488061/passing-multiple-parameters-to-controller-in-asp-net-mvc-also-generating-on-the
/// </remarks>
public class QueryStringFilterAttribute : ActionFilterAttribute
{
public string ParameterName { get; private set; }
public QueryStringFilterAttribute(string parameterName)
{
if (string.IsNullOrEmpty(parameterName))
throw new ArgumentException("ParameterName is required.");
ParameterName = parameterName;
}
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
var nonNullKeys = filterContext.HttpContext.Request.QueryString.AllKeys.Where(x => !string.IsNullOrEmpty(x));
var vals = nonNullKeys.ToDictionary(q => q, q => (object)filterContext.HttpContext.Request.QueryString[q]);
var qs = ToFormCollection(vals);
filterContext.ActionParameters[ParameterName] = qs;
base.OnActionExecuting(filterContext);
}
/// <summary>
/// Converts a dictionary to a FormCollection
/// </summary>
/// <param name="d"></param>
/// <returns></returns>
public static FormCollection ToFormCollection(IDictionary<string, object> d)
{
var n = new FormCollection();
foreach (var i in d)
{
n.Add(i.Key, Convert.ToString(i.Value));
}
return n;
}
}
}

View File

@@ -1,41 +0,0 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Web.Mvc;
using System.Web.Mvc.Async;
namespace Umbraco.Web.Mvc
{
/// <summary>
/// Ensures that if an action for the Template name is not explicitly defined by a user, that the 'Index' action will execute
/// </summary>
public class RenderActionInvoker : AsyncControllerActionInvoker
{
/// <summary>
/// Ensures that if an action for the Template name is not explicitly defined by a user, that the 'Index' action will execute
/// </summary>
/// <param name="controllerContext"></param>
/// <param name="controllerDescriptor"></param>
/// <param name="actionName"></param>
/// <returns></returns>
protected override ActionDescriptor FindAction(ControllerContext controllerContext, ControllerDescriptor controllerDescriptor, string actionName)
{
var ad = base.FindAction(controllerContext, controllerDescriptor, actionName);
//now we need to check if it exists, if not we need to return the Index by default
if (ad == null)
{
//check if the controller is an instance of IRenderController and find the index
if (controllerContext.Controller is IRenderController)
{
// ReSharper disable once Mvc.ActionNotResolved
return controllerDescriptor.FindAction(controllerContext, "Index");
}
}
return ad;
}
}
}

View File

@@ -1,11 +0,0 @@
using System.Web.Mvc;
namespace Umbraco.Web.Mvc
{
//Migrated to .NET Core
public class RenderMvcController : Controller, IRenderMvcController
{
}
}

View File

@@ -13,7 +13,8 @@ using Current = Umbraco.Web.Composing.Current;
namespace Umbraco.Web.Mvc
{
public class RenderRouteHandler : IRouteHandler
// NOTE: already migrated to netcore, just here since the below is referenced still
public class RenderRouteHandler
{
// Define reserved dictionary keys for controller, action and area specified in route additional values data
internal static class ReservedAdditionalKeys
@@ -22,186 +23,5 @@ namespace Umbraco.Web.Mvc
internal const string Action = "a";
internal const string Area = "ar";
}
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
private readonly IUmbracoContext _umbracoContext;
public RenderRouteHandler(IUmbracoContextAccessor umbracoContextAccessor, IControllerFactory controllerFactory, IShortStringHelper shortStringHelper)
{
_umbracoContextAccessor = umbracoContextAccessor ?? throw new ArgumentNullException(nameof(umbracoContextAccessor));
}
public RenderRouteHandler(IUmbracoContext umbracoContext, IControllerFactory controllerFactory, IShortStringHelper shortStringHelper)
{
_umbracoContext = umbracoContext ?? throw new ArgumentNullException(nameof(umbracoContext));
}
private IUmbracoContext UmbracoContext => _umbracoContext ?? _umbracoContextAccessor.UmbracoContext;
#region IRouteHandler Members
/// <summary>
/// Assigns the correct controller based on the Umbraco request and returns a standard MvcHandler to process the response,
/// this also stores the render model into the data tokens for the current RouteData.
/// </summary>
public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
if (UmbracoContext == null)
{
throw new NullReferenceException("There is no current UmbracoContext, it must be initialized before the RenderRouteHandler executes");
}
var request = UmbracoContext.PublishedRequest;
if (request == null)
{
throw new NullReferenceException("There is no current PublishedRequest, it must be initialized before the RenderRouteHandler executes");
}
return GetHandlerForRoute(requestContext, request);
}
#endregion
/// <summary>
/// Checks the request and query strings to see if it matches the definition of having a Surface controller
/// posted/get value, if so, then we return a PostedDataProxyInfo object with the correct information.
/// </summary>
internal static PostedDataProxyInfo GetFormInfo(RequestContext requestContext)
{
if (requestContext == null) throw new ArgumentNullException(nameof(requestContext));
// if it is a POST/GET then a value must be in the request
if (requestContext.HttpContext.Request.QueryString["ufprt"].IsNullOrWhiteSpace()
&& requestContext.HttpContext.Request.Form["ufprt"].IsNullOrWhiteSpace())
{
return null;
}
string encodedVal;
switch (requestContext.HttpContext.Request.RequestType)
{
case "POST":
// get the value from the request.
// this field will contain an encrypted version of the surface route vals.
encodedVal = requestContext.HttpContext.Request.Form["ufprt"];
break;
case "GET":
// this field will contain an encrypted version of the surface route vals.
encodedVal = requestContext.HttpContext.Request.QueryString["ufprt"];
break;
default:
return null;
}
if (!UmbracoHelper.DecryptAndValidateEncryptedRouteString(encodedVal, out var decodedParts))
return null;
foreach (var item in decodedParts.Where(x => new[] {
ReservedAdditionalKeys.Controller,
ReservedAdditionalKeys.Action,
ReservedAdditionalKeys.Area }.Contains(x.Key) == false))
{
// Populate route with additional values which aren't reserved values so they eventually to action parameters
requestContext.RouteData.Values[item.Key] = item.Value;
}
//return the proxy info without the surface id... could be a local controller.
return new PostedDataProxyInfo
{
ControllerName = HttpUtility.UrlDecode(decodedParts.Single(x => x.Key == ReservedAdditionalKeys.Controller).Value),
ActionName = HttpUtility.UrlDecode(decodedParts.Single(x => x.Key == ReservedAdditionalKeys.Action).Value),
Area = HttpUtility.UrlDecode(decodedParts.Single(x => x.Key == ReservedAdditionalKeys.Area).Value),
};
}
/// <summary>
/// Handles a posted form to an Umbraco URL and ensures the correct controller is routed to and that
/// the right DataTokens are set.
/// </summary>
internal static IHttpHandler HandlePostedValues(RequestContext requestContext, PostedDataProxyInfo postedInfo)
{
if (requestContext == null) throw new ArgumentNullException(nameof(requestContext));
if (postedInfo == null) throw new ArgumentNullException(nameof(postedInfo));
//set the standard route values/tokens
requestContext.RouteData.Values["controller"] = postedInfo.ControllerName;
requestContext.RouteData.Values["action"] = postedInfo.ActionName;
IHttpHandler handler;
//get the route from the defined routes
using (RouteTable.Routes.GetReadLock())
{
Route surfaceRoute;
//find the controller in the route table
var surfaceRoutes = RouteTable.Routes.OfType<Route>()
.Where(x => x.Defaults != null &&
x.Defaults.ContainsKey("controller") &&
x.Defaults["controller"].ToString().InvariantEquals(postedInfo.ControllerName) &&
// Only return surface controllers
x.DataTokens["umbraco"].ToString().InvariantEquals("surface") &&
// Check for area token if the area is supplied
(postedInfo.Area.IsNullOrWhiteSpace() ? !x.DataTokens.ContainsKey("area") : x.DataTokens["area"].ToString().InvariantEquals(postedInfo.Area)))
.ToList();
// If more than one route is found, find one with a matching action
if (surfaceRoutes.Count > 1)
{
surfaceRoute = surfaceRoutes.FirstOrDefault(x =>
x.Defaults["action"] != null &&
x.Defaults["action"].ToString().InvariantEquals(postedInfo.ActionName));
}
else
{
surfaceRoute = surfaceRoutes.FirstOrDefault();
}
if (surfaceRoute == null)
throw new InvalidOperationException("Could not find a Surface controller route in the RouteTable for controller name " + postedInfo.ControllerName);
//set the area if one is there.
if (surfaceRoute.DataTokens.ContainsKey("area"))
{
requestContext.RouteData.DataTokens["area"] = surfaceRoute.DataTokens["area"];
}
//set the 'Namespaces' token so the controller factory knows where to look to construct it
if (surfaceRoute.DataTokens.ContainsKey("Namespaces"))
{
requestContext.RouteData.DataTokens["Namespaces"] = surfaceRoute.DataTokens["Namespaces"];
}
handler = surfaceRoute.RouteHandler.GetHttpHandler(requestContext);
}
return handler;
}
/// <summary>
/// this will determine the controller and set the values in the route data
/// </summary>
internal IHttpHandler GetHandlerForRoute(RequestContext requestContext, IPublishedRequest request)
{
if (requestContext == null) throw new ArgumentNullException(nameof(requestContext));
if (request == null) throw new ArgumentNullException(nameof(request));
//var routeDef = GetUmbracoRouteDefinition(requestContext, request);
// TODO: Need to port this to netcore
// Need to check for a special case if there is form data being posted back to an Umbraco URL
var postedInfo = GetFormInfo(requestContext);
if (postedInfo != null)
{
return HandlePostedValues(requestContext, postedInfo);
}
// NOTE: Code here has been removed and ported to netcore
throw new NotSupportedException("This code was already ported to netcore");
}
}
}

View File

@@ -1,41 +0,0 @@
using System;
using System.Linq;
using System.Web.Mvc;
using System.Web.Routing;
namespace Umbraco.Web.Mvc
{
internal static class RouteValueDictionaryExtensions
{
/// <summary>
/// Converts a route value dictionary to a form collection
/// </summary>
/// <param name="items"></param>
/// <returns></returns>
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;
}
/// <summary>
/// Returns the value of a mandatory item in the route items
/// </summary>
/// <param name="items"></param>
/// <param name="key"> </param>
/// <returns></returns>
public static object GetRequiredObject(this RouteValueDictionary items, string key)
{
if (key == null) throw new ArgumentNullException("key");
if (items.Keys.Contains(key) == false)
throw new ArgumentNullException("The " + key + " parameter was not found but is required");
return items[key];
}
}
}

View File

@@ -1,16 +0,0 @@
using System.Web;
using System.Web.Routing;
namespace Umbraco.Web.Mvc
{
/// <summary>
/// Assigned to all SurfaceController's so that it returns our custom SurfaceMvcHandler to use for rendering
/// </summary>
internal class SurfaceRouteHandler : IRouteHandler
{
public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
return new UmbracoMvcHandler(requestContext);
}
}
}

View File

@@ -1,109 +0,0 @@
using System;
using System.Web;
using System.Web.Mvc;
using Umbraco.Core;
using Umbraco.Core.Configuration;
using Umbraco.Core.Security;
using Umbraco.Core.Configuration.Models;
using Umbraco.Web.Composing;
using Umbraco.Web.Security;
namespace Umbraco.Web.Mvc
{
// TODO: This has been migrated to netcore and can be removed when ready
public sealed class UmbracoAuthorizeAttribute : AuthorizeAttribute
{
// see note in HttpInstallAuthorizeAttribute
private readonly IBackOfficeSecurityAccessor _backOfficeSecurityAccessor;
private readonly IRuntimeState _runtimeState;
private readonly string _redirectUrl;
private IRuntimeState RuntimeState => _runtimeState ?? Current.RuntimeState;
private IBackOfficeSecurity BackOfficeSecurity => _backOfficeSecurityAccessor.BackOfficeSecurity ?? Current.BackOfficeSecurityAccessor.BackOfficeSecurity;
/// <summary>
/// THIS SHOULD BE ONLY USED FOR UNIT TESTS
/// </summary>
/// <param name="backofficeSecurityAccessor"></param>
/// <param name="runtimeState"></param>
public UmbracoAuthorizeAttribute(IBackOfficeSecurityAccessor backofficeSecurityAccessor, IRuntimeState runtimeState)
{
_backOfficeSecurityAccessor = backofficeSecurityAccessor ?? throw new ArgumentNullException(nameof(backofficeSecurityAccessor));
_runtimeState = runtimeState ?? throw new ArgumentNullException(nameof(runtimeState));
}
/// <summary>
/// Default constructor
/// </summary>
public UmbracoAuthorizeAttribute()
{ }
/// <summary>
/// Constructor specifying to redirect to the specified location if not authorized
/// </summary>
/// <param name="redirectUrl"></param>
public UmbracoAuthorizeAttribute(string redirectUrl)
{
_redirectUrl = redirectUrl ?? throw new ArgumentNullException(nameof(redirectUrl));
}
/// <summary>
/// Constructor specifying to redirect to the umbraco login page if not authorized
/// </summary>
/// <param name="redirectToUmbracoLogin"></param>
public UmbracoAuthorizeAttribute(bool redirectToUmbracoLogin)
{
if (redirectToUmbracoLogin)
{
_redirectUrl = new GlobalSettings().GetBackOfficePath(Current.HostingEnvironment).EnsureStartsWith("~");
}
}
/// <summary>
/// Ensures that the user must be in the Administrator or the Install role
/// </summary>
/// <param name="httpContext"></param>
/// <returns></returns>
protected override bool AuthorizeCore(HttpContextBase httpContext)
{
if (httpContext == null) throw new ArgumentNullException(nameof(httpContext));
try
{
// if not configured (install or upgrade) then we can continue
// otherwise we need to ensure that a user is logged in
return RuntimeState.Level == RuntimeLevel.Install
|| RuntimeState.Level == RuntimeLevel.Upgrade
|| (httpContext.User?.Identity?.IsAuthenticated ?? false);
}
catch (Exception)
{
return false;
}
}
/// <summary>
/// Override to ensure no redirect occurs
/// </summary>
/// <param name="filterContext"></param>
protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
{
if (_redirectUrl.IsNullOrWhiteSpace())
{
filterContext.Result = (ActionResult)new HttpUnauthorizedResult("You must login to view this resource.");
}
else
{
filterContext.Result = new RedirectResult(_redirectUrl);
}
// DON'T do a FormsAuth redirect... argh!! thankfully we're running .Net 4.5 :)
filterContext.RequestContext.HttpContext.Response.SuppressFormsAuthenticationRedirect = true;
}
}
}

View File

@@ -1,88 +0,0 @@
// using System;
// using System.Web.Mvc;
// using System.Web.Routing;
// using System.Web.SessionState;
// using Umbraco.Core;
// using Umbraco.Core.Composing;
// using Umbraco.Web.Composing;
//
// namespace Umbraco.Web.Mvc
// {
// /// <summary>
// /// Abstract filtered controller factory used for all Umbraco controller factory implementations
// /// </summary>
// public abstract class UmbracoControllerFactory : IFilteredControllerFactory
// {
// private readonly OverridenDefaultControllerFactory _innerFactory = new OverridenDefaultControllerFactory();
//
// public abstract bool CanHandle(RequestContext request);
//
// public virtual Type GetControllerType(RequestContext requestContext, string controllerName)
// {
// return _innerFactory.GetControllerType(requestContext, controllerName);
// }
//
// /// <summary>
// /// Creates the specified controller by using the specified request context.
// /// </summary>
// /// <returns>
// /// The controller.
// /// </returns>
// /// <param name="requestContext">The request context.</param><param name="controllerName">The name of the controller.</param>
// public virtual IController CreateController(RequestContext requestContext, string controllerName)
// {
// var controllerType = GetControllerType(requestContext, controllerName) ??
// _innerFactory.GetControllerType(
// requestContext,
// ControllerExtensions.GetControllerName(Current.DefaultRenderMvcControllerType));
//
// return _innerFactory.GetControllerInstance(requestContext, controllerType);
// }
//
// /// <summary>
// /// Gets the controller's session behavior.
// /// </summary>
// /// <returns>
// /// The controller's session behavior.
// /// </returns>
// /// <param name="requestContext">The request context.</param><param name="controllerName">The name of the controller whose session behavior you want to get.</param>
// public SessionStateBehavior GetControllerSessionBehavior(RequestContext requestContext, string controllerName)
// {
// return ((IControllerFactory)_innerFactory).GetControllerSessionBehavior(requestContext, controllerName);
// }
//
// /// <summary>
// /// Releases the specified controller.
// /// </summary>
// /// <param name="controller">The controller.</param>
// public virtual void ReleaseController(IController controller)
// {
// _innerFactory.ReleaseController(controller);
// }
//
// /// <summary>
// /// By default, <see cref="DefaultControllerFactory"/> only exposes <see cref="IControllerFactory.CreateController"/> which throws an exception
// /// if the controller is not found. Since we want to try creating a controller, and then fall back to <see cref="RenderMvcController"/> if one isn't found,
// /// this nested class changes the visibility of <see cref="DefaultControllerFactory"/>'s internal methods in order to not have to rely on a try-catch.
// /// </summary>
// /// <remarks></remarks>
// internal class OverridenDefaultControllerFactory : ContainerControllerFactory
// {
// public OverridenDefaultControllerFactory()
// : base(new Lazy<IFactory>(() => Current.Factory))
// { }
//
// public new IController GetControllerInstance(RequestContext requestContext, Type controllerType)
// {
// return base.GetControllerInstance(requestContext, controllerType);
// }
//
// public new Type GetControllerType(RequestContext requestContext, string controllerName)
// {
// return controllerName.IsNullOrWhiteSpace()
// ? null
// : base.GetControllerType(requestContext, controllerName);
// }
// }
// }
// }

View File

@@ -1,32 +0,0 @@
using System.Web.Mvc;
using System.Web.Routing;
namespace Umbraco.Web.Mvc
{
/// <summary>
/// MVC handler to facilitate the TemplateRenderer. This handler can execute an MVC request and return it as a string.
///
/// Original:
///
/// This handler also used to intercept creation of controllers and store it for later use.
/// This was needed for the 'return CurrentUmbracoPage()' surface controller functionality
/// because it needs to send data back to the page controller.
///
/// The creation of this controller has been moved to the UmbracoPageResult class which will create a controller when needed.
/// </summary>
internal class UmbracoMvcHandler : MvcHandler
{
public UmbracoMvcHandler(RequestContext requestContext)
: base(requestContext)
{
}
/// <summary>
/// This is used internally purely to render an Umbraco MVC template to string and shouldn't be used for anything else.
/// </summary>
internal void ExecuteUmbracoRequest()
{
base.ProcessRequest(RequestContext.HttpContext);
}
}
}

View File

@@ -1,130 +0,0 @@
using System;
using System.Text;
using System.Web;
using System.Web.Mvc;
using System.Web.WebPages;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Umbraco.Core;
using Umbraco.Core.Cache;
using Umbraco.Core.Configuration;
using Umbraco.Core.Configuration.Models;
using Umbraco.Core.Configuration.UmbracoSettings;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.Services;
using Umbraco.Core.Strings;
using Umbraco.Web.Models;
using Umbraco.Web.Routing;
using Umbraco.Web.Security;
using Current = Umbraco.Web.Composing.Current;
namespace Umbraco.Web.Mvc
{
// TODO: This has been ported to netcore, just needs testing
public abstract class UmbracoViewPage<TModel> : WebViewPage<TModel>
{
private readonly GlobalSettings _globalSettings;
private readonly ContentSettings _contentSettings;
private IUmbracoContext _umbracoContext;
private UmbracoHelper _helper;
/// <summary>
/// Gets or sets the database context.
/// </summary>
public ServiceContext Services { get; set; }
/// <summary>
/// Gets or sets the application cache.
/// </summary>
public AppCaches AppCaches { get; set; }
// TODO: previously, Services and ApplicationCache would derive from UmbracoContext.Application, which
// was an ApplicationContext - so that everything derived from UmbracoContext.
// UmbracoContext is fetched from the data tokens, thus allowing the view to be rendered with a
// custom context and NOT the Current.UmbracoContext - eg outside the normal Umbraco routing
// process.
// leaving it as-it for the time being but really - the UmbracoContext should be injected just
// like the Services & ApplicationCache properties, and have a setter for those special weird
// cases.
// TODO: Can be injected to the view in netcore, else injected to the base model
// public IUmbracoContext UmbracoContext => _umbracoContext
// ?? (_umbracoContext = ViewContext.GetUmbracoContext() ?? Current.UmbracoContext);
/// <summary>
/// Gets the public content request.
/// </summary>
internal IPublishedRequest PublishedRequest
{
get
{
// TODO: we only have one data token for a route now: Constants.Web.UmbracoRouteDefinitionDataToken
throw new NotImplementedException("Probably needs to be ported to netcore");
//// we should always try to return the object from the data tokens just in case its a custom object and not
//// the one from UmbracoContext. Fallback to UmbracoContext if necessary.
//// try view context
//if (ViewContext.RouteData.DataTokens.ContainsKey(Constants.Web.UmbracoRouteDefinitionDataToken))
//{
// return (IPublishedRequest) ViewContext.RouteData.DataTokens.GetRequiredObject(Constants.Web.UmbracoRouteDefinitionDataToken);
//}
//// child action, try parent view context
//if (ViewContext.IsChildAction && ViewContext.ParentActionViewContext.RouteData.DataTokens.ContainsKey(Constants.Web.UmbracoRouteDefinitionDataToken))
//{
// return (IPublishedRequest) ViewContext.ParentActionViewContext.RouteData.DataTokens.GetRequiredObject(Constants.Web.UmbracoRouteDefinitionDataToken);
//}
//// fallback to UmbracoContext
//return UmbracoContext.PublishedRequest;
}
}
/// <summary>
/// Gets the Umbraco helper.
/// </summary>
public UmbracoHelper Umbraco
{
get
{
if (_helper != null) return _helper;
var model = ViewData.Model;
var content = model as IPublishedContent;
if (content == null && model is IContentModel)
content = ((IContentModel) model).Content;
_helper = Current.UmbracoHelper;
if (content != null)
_helper.AssignedContentItem = content;
return _helper;
}
}
protected UmbracoViewPage()
: this(
Current.Factory.GetRequiredService<ServiceContext>(),
Current.Factory.GetRequiredService<AppCaches>(),
Current.Factory.GetRequiredService<IOptions<GlobalSettings>>(),
Current.Factory.GetRequiredService<IOptions<ContentSettings>>()
)
{
}
protected UmbracoViewPage(ServiceContext services, AppCaches appCaches, IOptions<GlobalSettings> globalSettings, IOptions<ContentSettings> contentSettings)
{
if (globalSettings == null) throw new ArgumentNullException(nameof(globalSettings));
if (contentSettings == null) throw new ArgumentNullException(nameof(contentSettings));
Services = services;
AppCaches = appCaches;
_globalSettings = globalSettings.Value;
_contentSettings = contentSettings.Value;
}
}
}

View File

@@ -1,62 +0,0 @@
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Web.Mvc;
using Umbraco.Core;
namespace Umbraco.Web.Mvc
{
/// <summary>
/// Attribute used to check that the request contains a valid Umbraco form request string.
/// </summary>
/// <seealso cref="System.Web.Mvc.FilterAttribute" />
/// <seealso cref="System.Web.Mvc.IAuthorizationFilter" />
/// <remarks>
/// Applying this attribute/filter to a <see cref="SurfaceController"/> or SurfaceController Action will ensure that the Action can only be executed
/// when it is routed to from within Umbraco, typically when rendering a form with BeginUmbracoForm. It will mean that the natural MVC route for this Action
/// will fail with a <see cref="HttpUmbracoFormRouteStringException"/>.
/// </remarks>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public sealed class ValidateUmbracoFormRouteStringAttribute : FilterAttribute, IAuthorizationFilter
{
/// <summary>
/// Called when authorization is required.
/// </summary>
/// <param name="filterContext">The filter context.</param>
/// <exception cref="ArgumentNullException">filterContext</exception>
/// <exception cref="Umbraco.Web.Mvc.HttpUmbracoFormRouteStringException">The required request field \"ufprt\" is not present.
/// or
/// The Umbraco form request route string could not be decrypted.
/// or
/// The provided Umbraco form request route string was meant for a different controller and action.</exception>
public void OnAuthorization(AuthorizationContext filterContext)
{
if (filterContext == null)
throw new ArgumentNullException(nameof(filterContext));
var ufprt = filterContext.HttpContext.Request["ufprt"];
ValidateRouteString(ufprt, filterContext.ActionDescriptor?.ControllerDescriptor.ControllerName, filterContext.ActionDescriptor?.ActionName, filterContext.RouteData?.DataTokens["area"]?.ToString());
}
public void ValidateRouteString(string ufprt, string currentController, string currentAction, string currentArea)
{
if (ufprt.IsNullOrWhiteSpace())
{
throw new HttpUmbracoFormRouteStringException("The required request field \"ufprt\" is not present.");
}
if (!UmbracoHelper.DecryptAndValidateEncryptedRouteString(ufprt, out var additionalDataParts))
{
throw new HttpUmbracoFormRouteStringException("The Umbraco form request route string could not be decrypted.");
}
if (!additionalDataParts[RenderRouteHandler.ReservedAdditionalKeys.Controller].InvariantEquals(currentController) ||
!additionalDataParts[RenderRouteHandler.ReservedAdditionalKeys.Action].InvariantEquals(currentAction) ||
(!additionalDataParts[RenderRouteHandler.ReservedAdditionalKeys.Area].IsNullOrWhiteSpace() && !additionalDataParts[RenderRouteHandler.ReservedAdditionalKeys.Area].InvariantEquals(currentArea)))
{
throw new HttpUmbracoFormRouteStringException("The provided Umbraco form request route string was meant for a different controller and action.");
}
}
}
}

View File

@@ -1,49 +0,0 @@
using System.Web.Mvc;
namespace Umbraco.Web.Mvc
{
internal static class ViewDataContainerExtensions
{
private class ViewDataContainer : IViewDataContainer
{
public ViewDataContainer()
{
ViewData = new ViewDataDictionary();
}
public ViewDataDictionary ViewData { get; set; }
}
/// <summary>
/// Creates a new IViewDataContainer but with a filtered ModelState
/// </summary>
/// <param name="container"></param>
/// <param name="prefix"></param>
/// <returns></returns>
public static IViewDataContainer FilterContainer(this IViewDataContainer container, string prefix)
{
var newContainer = new ViewDataContainer();
newContainer.ViewData.ModelState.Merge(container.ViewData.ModelState, prefix);
//change the HTML field name too
newContainer.ViewData.TemplateInfo.HtmlFieldPrefix = prefix;
return newContainer;
}
/// <summary>
/// Returns a new IViewContainer based on the current one but supplies a different model to the ViewData
/// </summary>
/// <param name="container"></param>
/// <param name="model"></param>
/// <returns></returns>
public static IViewDataContainer CopyWithModel(this IViewDataContainer container, object model)
{
return new ViewDataContainer
{
ViewData = new ViewDataDictionary(container.ViewData)
{
Model = model
}
};
}
}
}

View File

@@ -1,123 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
using System.Web.Http.Dispatcher;
using System.Web.Mvc;
using System.Web.Routing;
using Umbraco.Core;
using Umbraco.Core.Composing;
using Umbraco.Core.Configuration;
using Umbraco.Core.Configuration.Models;
using Umbraco.Core.Hosting;
using Umbraco.Core.Strings;
using Umbraco.Web.Mvc;
using Umbraco.Web.WebApi;
using Constants = Umbraco.Core.Constants;
using Current = Umbraco.Web.Composing.Current;
namespace Umbraco.Web.Runtime
{
public sealed class WebInitialComponent : IComponent
{
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
private readonly UmbracoApiControllerTypeCollection _apiControllerTypes;
private readonly GlobalSettings _globalSettings;
private readonly IHostingEnvironment _hostingEnvironment;
private readonly IShortStringHelper _shortStringHelper;
public WebInitialComponent(
IUmbracoContextAccessor umbracoContextAccessor,
UmbracoApiControllerTypeCollection apiControllerTypes,
GlobalSettings globalSettings,
IHostingEnvironment hostingEnvironment,
IShortStringHelper shortStringHelper)
{
_umbracoContextAccessor = umbracoContextAccessor;
_apiControllerTypes = apiControllerTypes;
_globalSettings = globalSettings;
_hostingEnvironment = hostingEnvironment;
_shortStringHelper = shortStringHelper;
}
public void Initialize()
{
// setup mvc and webapi services
SetupMvcAndWebApi();
// Disable the X-AspNetMvc-Version HTTP Header
MvcHandler.DisableMvcResponseHeader = true;
// wrap view engines in the profiling engine
WrapViewEngines(ViewEngines.Engines);
// add global filters
ConfigureGlobalFilters();
// set routes
CreateRoutes(_umbracoContextAccessor, _globalSettings, _shortStringHelper, _apiControllerTypes, _hostingEnvironment);
}
public void Terminate()
{ }
private static void ConfigureGlobalFilters()
{
//GlobalFilters.Filters.Add(new EnsurePartialViewMacroViewContextFilterAttribute());
}
// internal for tests
internal static void WrapViewEngines(IList<IViewEngine> viewEngines)
{
if (viewEngines == null || viewEngines.Count == 0) return;
var originalEngines = viewEngines.ToList();
viewEngines.Clear();
foreach (var engine in originalEngines)
{
var wrappedEngine = engine;// TODO introduce in NETCORE: is ProfilingViewEngine ? engine : new ProfilingViewEngine(engine);
viewEngines.Add(wrappedEngine);
}
}
private void SetupMvcAndWebApi()
{
//don't output the MVC version header (security)
//MvcHandler.DisableMvcResponseHeader = true;
// set master controller factory
// var controllerFactory = new MasterControllerFactory(() => Current.FilteredControllerFactories);
// ControllerBuilder.Current.SetControllerFactory(controllerFactory);
// set the render & plugin view engines
// ViewEngines.Engines.Add(new RenderViewEngine(_hostingEnvironment));
// ViewEngines.Engines.Add(new PluginViewEngine());
////add the profiling action filter
//GlobalFilters.Filters.Add(new ProfilingActionFilter());
GlobalConfiguration.Configuration.Services.Replace(typeof(IHttpControllerSelector),
new NamespaceHttpControllerSelector(GlobalConfiguration.Configuration));
}
// internal for tests
internal static void CreateRoutes(
IUmbracoContextAccessor umbracoContextAccessor,
GlobalSettings globalSettings,
IShortStringHelper shortStringHelper,
UmbracoApiControllerTypeCollection apiControllerTypes,
IHostingEnvironment hostingEnvironment)
{
var umbracoPath = globalSettings.GetUmbracoMvcArea(hostingEnvironment);
// create the front-end route
var defaultRoute = RouteTable.Routes.MapRoute(
"Umbraco_default",
umbracoPath + "/RenderMvc/{action}/{id}",
new { controller = "RenderMvc", action = "Index", id = UrlParameter.Optional }
);
defaultRoute.RouteHandler = new RenderRouteHandler(umbracoContextAccessor, ControllerBuilder.Current.GetControllerFactory(), shortStringHelper);
}
}
}

View File

@@ -1,67 +0,0 @@
using System.Web.Security;
using Microsoft.Extensions.DependencyInjection;
using Umbraco.Core;
using Umbraco.Core.DependencyInjection;
using Umbraco.Core.Composing;
using Umbraco.Core.Dictionary;
using Umbraco.Core.Templates;
using Umbraco.Core.Security;
using Umbraco.Core.Services;
using Umbraco.Web.Macros;
using Umbraco.Web.PublishedCache;
using Umbraco.Web.Security;
using Umbraco.Web.Security.Providers;
namespace Umbraco.Web.Runtime
{
[ComposeBefore(typeof(ICoreComposer))]
public sealed class WebInitialComposer : ComponentComposer<WebInitialComponent>
{
public override void Compose(IUmbracoBuilder builder)
{
base.Compose(builder);
// register membership stuff
builder.Services.AddTransient(factory => MembershipProviderExtensions.GetMembersMembershipProvider());
builder.Services.AddTransient(factory => Roles.Enabled ? Roles.Provider : new MembersRoleProvider(factory.GetRequiredService<IMemberService>()));
builder.Services.AddScoped<MembershipHelper>();
builder.Services.AddTransient<IPublishedMemberCache>(factory => factory.GetRequiredService<IUmbracoContext>().PublishedSnapshot.Members);
builder.Services.AddUnique<IMemberUserKeyProvider, MemberUserKeyProvider>();
builder.Services.AddUnique<IPublicAccessChecker, PublicAccessChecker>();
builder.Services.AddTransient<UmbracoHelper>(factory =>
{
var state = factory.GetRequiredService<IRuntimeState>();
if (state.Level == RuntimeLevel.Run)
{
var umbCtx = factory.GetRequiredService<IUmbracoContext>();
return new UmbracoHelper(umbCtx.IsFrontEndUmbracoRequest() ? umbCtx.PublishedRequest?.PublishedContent : null, factory.GetRequiredService<ICultureDictionaryFactory>(),
factory.GetRequiredService<IUmbracoComponentRenderer>(), factory.GetRequiredService<IPublishedContentQuery>(), factory.GetRequiredService<MembershipHelper>());
}
return new UmbracoHelper();
});
// configure the container for web
//composition.ConfigureForWeb();
//composition
/* TODO: This will depend on if we use ServiceBasedControllerActivator - see notes in Startup.cs
* You will likely need to set DefaultRenderMvcControllerType on Umbraco.Web.Composing.Current
* which is what the extension method below did previously.
*/
//.ComposeUmbracoControllers(GetType().Assembly)
//.SetDefaultRenderMvcController</*RenderMvcController*/ Controller>(); // default controller for template views
//we need to eagerly scan controller types since they will need to be routed
// composition.WithCollectionBuilder<SurfaceControllerTypeCollectionBuilder>()
// .Add(composition.TypeLoader.GetSurfaceControllers());
// auto-register views
//composition.RegisterAuto(typeof(UmbracoViewPage<>));
}
}
}

View File

@@ -137,16 +137,10 @@
<Compile Include="AspNet\AspNetUmbracoApplicationLifetime.cs" />
<Compile Include="HttpContextExtensions.cs" />
<Compile Include="Macros\MemberUserKeyProvider.cs" />
<Compile Include="Mvc\IRenderController.cs" />
<Compile Include="Mvc\IRenderMvcController.cs" />
<Compile Include="Mvc\MemberAuthorizeAttribute.cs" />
<Compile Include="Mvc\RenderMvcController.cs" />
<Compile Include="Mvc\UmbracoViewPageOfTModel.cs" />
<Compile Include="Security\BackOfficeSecurity.cs" />
<Compile Include="HttpContextAccessorExtensions.cs" />
<Compile Include="Models\Membership\UmbracoMembershipMember.cs" />
<Compile Include="Mvc\HttpUmbracoFormRouteStringException.cs" />
<Compile Include="Mvc\ValidateUmbracoFormRouteStringAttribute.cs" />
<Compile Include="AspNet\AspNetBackOfficeInfo.cs" />
<Compile Include="AspNet\AspNetCookieManager.cs" />
<Compile Include="AspNet\AspNetHttpContextAccessor.cs" />
@@ -162,7 +156,6 @@
<Compile Include="UmbracoContextFactory.cs" />
<Compile Include="Mvc\UmbracoVirtualNodeByUdiRouteHandler.cs" />
<Compile Include="UmbracoDbProviderFactoryCreator.cs" />
<Compile Include="Runtime\WebInitialComposer.cs" />
<Compile Include="Security\ActiveDirectoryBackOfficeUserPasswordChecker.cs" />
<Compile Include="Security\BackOfficeUserPasswordCheckerResult.cs" />
<Compile Include="Security\IBackOfficeUserPasswordChecker.cs" />
@@ -179,9 +172,6 @@
<Compile Include="WebApi\Filters\FeatureAuthorizeAttribute.cs" />
<Compile Include="WebApi\SessionHttpControllerRouteHandler.cs" />
<Compile Include="WebApi\UmbracoApiControllerTypeCollectionBuilder.cs" />
<Compile Include="Runtime\WebInitialComponent.cs" />
<Compile Include="Mvc\ProfilingView.cs" />
<Compile Include="Mvc\NotFoundHandler.cs" />
<Compile Include="Mvc\UmbracoVirtualNodeByIdRouteHandler.cs" />
<Compile Include="Mvc\EnsurePublishedContentRequestAttribute.cs" />
<Compile Include="Mvc\UmbracoVirtualNodeRouteHandler.cs" />
@@ -194,10 +184,6 @@
<Compile Include="Security\Providers\MembersRoleProvider.cs" />
<Compile Include="Security\Providers\UmbracoMembershipProvider.cs" />
<Compile Include="HttpRequestExtensions.cs" />
<Compile Include="Mvc\AreaRegistrationExtensions.cs" />
<Compile Include="Mvc\QueryStringFilterAttribute.cs" />
<Compile Include="Mvc\ControllerFactoryExtensions.cs" />
<Compile Include="Mvc\SurfaceRouteHandler.cs" />
<Compile Include="UrlHelperExtensions.cs" />
<Compile Include="UrlHelperRenderExtensions.cs" />
<Compile Include="WebApi\IsBackOfficeAttribute.cs" />
@@ -206,14 +192,9 @@
<Compile Include="WebApi\NamespaceHttpControllerSelector.cs" />
<Compile Include="WebApi\UmbracoApiController.cs" />
<Compile Include="WebApi\UmbracoApiControllerBase.cs" />
<Compile Include="Mvc\UmbracoAuthorizeAttribute.cs" />
<Compile Include="Mvc\NotChildAction.cs" />
<Compile Include="Mvc\UmbracoControllerFactory.cs" />
<Compile Include="Mvc\UmbracoMvcHandler.cs" />
<Compile Include="ModelStateExtensions.cs" />
<Compile Include="Mvc\MergeModelStateToChildActionAttribute.cs" />
<Compile Include="Mvc\PluginController.cs" />
<Compile Include="Mvc\PostedDataProxyInfo.cs" />
<Compile Include="Mvc\Strings.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
@@ -223,11 +204,8 @@
<Compile Include="Mvc\PluginControllerAttribute.cs" />
<Compile Include="RouteCollectionExtensions.cs" />
<Compile Include="UmbracoHelper.cs" />
<Compile Include="Mvc\ViewDataContainerExtensions.cs" />
<Compile Include="Mvc\RenderActionInvoker.cs" />
<Compile Include="Mvc\RenderRouteHandler.cs" />
<Compile Include="Mvc\RouteDefinition.cs" />
<Compile Include="Mvc\RouteValueDictionaryExtensions.cs" />
<Compile Include="WebApi\UmbracoAuthorizeAttribute.cs" />
<Compile Include="WebApi\UmbracoAuthorizedApiController.cs" />
<Compile Include="WebApi\Filters\ValidationFilterAttribute.cs" />
@@ -255,8 +233,6 @@
<Link>Mvc\web.config</Link>
</None>
</ItemGroup>
<ItemGroup>
<Folder Include="Install\InstallSteps\" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>