Changes the umbraco route values to use http features intead of in route values which is much nicer, fixes the redirect to page result, tests a surface controller POST and it works, ensures the routing takes place before the form check, removes a bunch of old code

This commit is contained in:
Shannon
2021-02-03 15:47:27 +11:00
parent 2dc169457b
commit 0c26a82489
28 changed files with 313 additions and 902 deletions

View File

@@ -1,278 +0,0 @@
using System;
using System.Collections.Specialized;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Web.Composing;
using Umbraco.Web.Routing;
namespace Umbraco.Web.Mvc
{
/// <summary>
/// Redirects to an Umbraco page by Id or Entity
/// </summary>
/// Migrated already to .Net Core
public class RedirectToUmbracoPageResult : ActionResult
{
private IPublishedContent _publishedContent;
private readonly int _pageId;
private readonly Guid _key;
private NameValueCollection _queryStringValues;
private IPublishedUrlProvider _publishedUrlProvider;
private string _url;
public string Url
{
get
{
if (!_url.IsNullOrWhiteSpace()) return _url;
if (PublishedContent == null)
{
throw new InvalidOperationException(string.Format("Cannot redirect, no entity was found for id {0}", _pageId));
}
var result = _publishedUrlProvider.GetUrl(PublishedContent.Id);
if (result != "#")
{
_url = result;
return _url;
}
throw new InvalidOperationException(string.Format("Could not route to entity with id {0}, the NiceUrlProvider could not generate a URL", _pageId));
}
}
public int PageId
{
get { return _pageId; }
}
public Guid Key
{
get { return _key; }
}
public IPublishedContent PublishedContent
{
get
{
if (_publishedContent != null) return _publishedContent;
if (_pageId != default(int))
{
_publishedContent = Current.UmbracoContext.Content.GetById(_pageId);
}
else if (_key != default(Guid))
{
_publishedContent = Current.UmbracoContext.Content.GetById(_key);
}
return _publishedContent;
}
}
/// <summary>
/// Creates a new RedirectToUmbracoResult
/// </summary>
/// <param name="pageId"></param>
public RedirectToUmbracoPageResult(int pageId)
: this(pageId, Current.PublishedUrlProvider)
{
}
/// <summary>
/// Creates a new RedirectToUmbracoResult
/// </summary>
/// <param name="pageId"></param>
/// <param name="queryStringValues"></param>
public RedirectToUmbracoPageResult(int pageId, NameValueCollection queryStringValues)
: this(pageId, queryStringValues, Current.PublishedUrlProvider)
{
}
/// <summary>
/// Creates a new RedirectToUmbracoResult
/// </summary>
/// <param name="pageId"></param>
/// <param name="queryString"></param>
public RedirectToUmbracoPageResult(int pageId, string queryString)
: this(pageId, queryString, Current.PublishedUrlProvider)
{
}
/// <summary>
/// Creates a new RedirectToUmbracoResult
/// </summary>
/// <param name="publishedContent"></param>
public RedirectToUmbracoPageResult(IPublishedContent publishedContent)
: this(publishedContent, Current.PublishedUrlProvider)
{
}
/// <summary>
/// Creates a new RedirectToUmbracoResult
/// </summary>
/// <param name="publishedContent"></param>
/// <param name="queryStringValues"></param>
public RedirectToUmbracoPageResult(IPublishedContent publishedContent, NameValueCollection queryStringValues)
: this(publishedContent, queryStringValues, Current.PublishedUrlProvider)
{
}
/// <summary>
/// Creates a new RedirectToUmbracoResult
/// </summary>
/// <param name="queryString"></param>
/// <param name="queryStringValues"></param>
public RedirectToUmbracoPageResult(IPublishedContent publishedContent, string queryString)
: this(publishedContent, queryString, Current.PublishedUrlProvider)
{
}
/// <summary>
/// Creates a new RedirectToUmbracoResult
/// </summary>
/// <param name="pageId"></param>
/// <param name="umbracoContextAccessor"></param>
public RedirectToUmbracoPageResult(int pageId, IPublishedUrlProvider publishedUrlProvider)
{
_pageId = pageId;
_publishedUrlProvider = publishedUrlProvider;
}
/// <summary>
/// Creates a new RedirectToUmbracoResult
/// </summary>
/// <param name="pageId"></param>
/// <param name="queryStringValues"></param>
/// <param name="umbracoContextAccessor"></param>
public RedirectToUmbracoPageResult(int pageId, NameValueCollection queryStringValues, IPublishedUrlProvider publishedUrlProvider)
{
_pageId = pageId;
_queryStringValues = queryStringValues;
_publishedUrlProvider = publishedUrlProvider;
}
/// <summary>
/// Creates a new RedirectToUmbracoResult
/// </summary>
/// <param name="pageId"></param>
/// <param name="queryString"></param>
/// <param name="umbracoContextAccessor"></param>
public RedirectToUmbracoPageResult(int pageId, string queryString, IPublishedUrlProvider publishedUrlProvider)
{
_pageId = pageId;
_queryStringValues = ParseQueryString(queryString);
_publishedUrlProvider = publishedUrlProvider;
}
/// <summary>
/// Creates a new RedirectToUmbracoResult
/// </summary>
/// <param name="key"></param>
/// <param name="umbracoContextAccessor"></param>
public RedirectToUmbracoPageResult(Guid key)
{
_key = key;
}
/// <summary>
/// Creates a new RedirectToUmbracoResult
/// </summary>
/// <param name="key"></param>
/// <param name="queryStringValues"></param>
public RedirectToUmbracoPageResult(Guid key, NameValueCollection queryStringValues)
{
_key = key;
_queryStringValues = queryStringValues;
}
/// <summary>
/// Creates a new RedirectToUmbracoResult
/// </summary>
/// <param name="key"></param>
/// <param name="queryString"></param>
public RedirectToUmbracoPageResult(Guid key, string queryString)
{
_key = key;
_queryStringValues = ParseQueryString(queryString);
}
/// <summary>
/// Creates a new RedirectToUmbracoResult
/// </summary>
/// <param name="publishedContent"></param>
/// <param name="umbracoContextAccessor"></param>
public RedirectToUmbracoPageResult(IPublishedContent publishedContent, IPublishedUrlProvider publishedUrlProvider)
{
_publishedContent = publishedContent;
_pageId = publishedContent.Id;
_publishedUrlProvider = publishedUrlProvider;
}
/// <summary>
/// Creates a new RedirectToUmbracoResult
/// </summary>
/// <param name="publishedContent"></param>
/// <param name="queryStringValues"></param>
/// <param name="umbracoContextAccessor"></param>
public RedirectToUmbracoPageResult(IPublishedContent publishedContent, NameValueCollection queryStringValues, IPublishedUrlProvider publishedUrlProvider)
{
_publishedContent = publishedContent;
_pageId = publishedContent.Id;
_queryStringValues = queryStringValues;
_publishedUrlProvider = publishedUrlProvider;
}
/// <summary>
/// Creates a new RedirectToUmbracoResult
/// </summary>
/// <param name="publishedContent"></param>
/// <param name="queryString"></param>
/// <param name="umbracoContextAccessor"></param>
public RedirectToUmbracoPageResult(IPublishedContent publishedContent, string queryString, IPublishedUrlProvider publishedUrlProvider)
{
_publishedContent = publishedContent;
_pageId = publishedContent.Id;
_queryStringValues = ParseQueryString(queryString);
_publishedUrlProvider = publishedUrlProvider;
}
public override void ExecuteResult(ControllerContext context)
{
if (context == null) throw new ArgumentNullException("context");
if (context.IsChildAction)
{
throw new InvalidOperationException("Cannot redirect from a Child Action");
}
var destinationUrl = UrlHelper.GenerateContentUrl(Url, context.HttpContext);
if (_queryStringValues != null && _queryStringValues.Count > 0)
{
destinationUrl = destinationUrl += "?" + string.Join("&",
_queryStringValues.AllKeys.Select(x => x + "=" + HttpUtility.UrlEncode(_queryStringValues[x])));
}
context.Controller.TempData.Keep();
context.HttpContext.Response.Redirect(destinationUrl, endResponse: false);
}
private NameValueCollection ParseQueryString(string queryString)
{
if (!string.IsNullOrEmpty(queryString))
{
return HttpUtility.ParseQueryString(queryString);
}
return null;
}
}
}

View File

@@ -1,43 +0,0 @@
using System;
using System.Web.Mvc;
namespace Umbraco.Web.Mvc
{
/// <summary>
/// Redirects to the current URL rendering an Umbraco page including it's query strings
/// </summary>
/// <remarks>
/// This is useful if you need to redirect
/// to the current page but the current page is actually a rewritten URL normally done with something like
/// Server.Transfer. It is also handy if you want to persist the query strings.
/// </remarks>
/// Migrated already to .Net Core
public class RedirectToUmbracoUrlResult : ActionResult
{
private readonly IUmbracoContext _umbracoContext;
/// <summary>
/// Creates a new RedirectToUmbracoResult
/// </summary>
/// <param name="umbracoContext"></param>
public RedirectToUmbracoUrlResult(IUmbracoContext umbracoContext)
{
_umbracoContext = umbracoContext;
}
public override void ExecuteResult(ControllerContext context)
{
if (context == null) throw new ArgumentNullException("context");
if (context.IsChildAction)
{
throw new InvalidOperationException("Cannot redirect from a Child Action");
}
var destinationUrl = _umbracoContext.OriginalRequestUrl.PathAndQuery;
context.Controller.TempData.Keep();
context.HttpContext.Response.Redirect(destinationUrl, endResponse: false);
}
}
}

View File

@@ -3,16 +3,12 @@ using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.Web.SessionState;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Umbraco.Core;
using Umbraco.Core.Composing;
using Umbraco.Core.Strings;
using Umbraco.Web.Features;
using Umbraco.Web.Models;
using Umbraco.Web.Routing;
using Umbraco.Core.Strings;
using Current = Umbraco.Web.Composing.Current;
namespace Umbraco.Web.Mvc
@@ -27,29 +23,21 @@ namespace Umbraco.Web.Mvc
internal const string Area = "ar";
}
private readonly IControllerFactory _controllerFactory;
private readonly IShortStringHelper _shortStringHelper;
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
private readonly IUmbracoContext _umbracoContext;
public RenderRouteHandler(IUmbracoContextAccessor umbracoContextAccessor, IControllerFactory controllerFactory, IShortStringHelper shortStringHelper)
{
_umbracoContextAccessor = umbracoContextAccessor ?? throw new ArgumentNullException(nameof(umbracoContextAccessor));
_controllerFactory = controllerFactory ?? throw new ArgumentNullException(nameof(controllerFactory));
_shortStringHelper = shortStringHelper ?? throw new ArgumentNullException(nameof(shortStringHelper));
}
public RenderRouteHandler(IUmbracoContext umbracoContext, IControllerFactory controllerFactory, IShortStringHelper shortStringHelper)
{
_umbracoContext = umbracoContext ?? throw new ArgumentNullException(nameof(umbracoContext));
_controllerFactory = controllerFactory ?? throw new ArgumentNullException(nameof(controllerFactory));
_shortStringHelper = shortStringHelper ?? throw new ArgumentNullException(nameof(shortStringHelper));
}
private IUmbracoContext UmbracoContext => _umbracoContext ?? _umbracoContextAccessor.UmbracoContext;
private UmbracoFeatures Features => Current.Factory.GetRequiredService<UmbracoFeatures>(); // TODO: inject
#region IRouteHandler Members
/// <summary>
@@ -74,26 +62,15 @@ namespace Umbraco.Web.Mvc
#endregion
private void UpdateRouteDataForRequest(ContentModel contentModel, RequestContext requestContext)
{
if (contentModel == null) throw new ArgumentNullException(nameof(contentModel));
if (requestContext == null) throw new ArgumentNullException(nameof(requestContext));
// requestContext.RouteData.DataTokens[Core.Constants.Web.UmbracoDataToken] = contentModel;
// the rest should not change -- it's only the published content that has changed
}
/// <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>
/// <param name="requestContext"></param>
/// <returns></returns>
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 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())
{
@@ -105,12 +82,12 @@ namespace Umbraco.Web.Mvc
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.
// 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.
// this field will contain an encrypted version of the surface route vals.
encodedVal = requestContext.HttpContext.Request.QueryString["ufprt"];
break;
default:
@@ -144,8 +121,6 @@ namespace Umbraco.Web.Mvc
/// Handles a posted form to an Umbraco URL and ensures the correct controller is routed to and that
/// the right DataTokens are set.
/// </summary>
/// <param name="requestContext"></param>
/// <param name="postedInfo"></param>
internal static IHttpHandler HandlePostedValues(RequestContext requestContext, PostedDataProxyInfo postedInfo)
{
if (requestContext == null) throw new ArgumentNullException(nameof(requestContext));

View File

@@ -10,9 +10,6 @@ using Umbraco.Web.Composing;
namespace Umbraco.Web.Mvc
{
/// <summary>
/// Provides a base class for front-end add-in controllers.
/// </summary>
/// Migrated already to .Net Core without MergeModelStateToChildAction and MergeParentContextViewData action filters
/// TODO: Migrate MergeModelStateToChildAction and MergeParentContextViewData action filters
[MergeModelStateToChildAction]
@@ -26,197 +23,5 @@ namespace Umbraco.Web.Mvc
: base(umbracoContextAccessor, databaseFactory, services, appCaches,profilingLogger)
{ }
/// <summary>
/// Redirects to the Umbraco page with the given id
/// </summary>
/// <param name="pageId"></param>
/// <returns></returns>
protected RedirectToUmbracoPageResult RedirectToUmbracoPage(int pageId)
{
return new RedirectToUmbracoPageResult(pageId, Current.PublishedUrlProvider);
}
/// <summary>
/// Redirects to the Umbraco page with the given id and passes provided querystring
/// </summary>
/// <param name="pageId"></param>
/// <param name="queryStringValues"></param>
/// <returns></returns>
protected RedirectToUmbracoPageResult RedirectToUmbracoPage(int pageId, NameValueCollection queryStringValues)
{
return new RedirectToUmbracoPageResult(pageId, queryStringValues, Current.PublishedUrlProvider);
}
/// <summary>
/// Redirects to the Umbraco page with the given id and passes provided querystring
/// </summary>
/// <param name="pageId"></param>
/// <param name="queryString"></param>
/// <returns></returns>
protected RedirectToUmbracoPageResult RedirectToUmbracoPage(int pageId, string queryString)
{
return new RedirectToUmbracoPageResult(pageId, queryString, Current.PublishedUrlProvider);
}
/// <summary>
/// Redirects to the Umbraco page with the given id
/// </summary>
/// <param name="pageId"></param>
/// <returns></returns>
protected RedirectToUmbracoPageResult RedirectToUmbracoPage(Guid key)
{
return new RedirectToUmbracoPageResult(key);
}
/// <summary>
/// Redirects to the Umbraco page with the given id and passes provided querystring
/// </summary>
/// <param name="pageId"></param>
/// <param name="queryStringValues"></param>
/// <returns></returns>
protected RedirectToUmbracoPageResult RedirectToUmbracoPage(Guid key, NameValueCollection queryStringValues)
{
return new RedirectToUmbracoPageResult(key, queryStringValues);
}
/// <summary>
/// Redirects to the Umbraco page with the given id and passes provided querystring
/// </summary>
/// <param name="pageId"></param>
/// <param name="queryString"></param>
/// <returns></returns>
protected RedirectToUmbracoPageResult RedirectToUmbracoPage(Guid key, string queryString)
{
return new RedirectToUmbracoPageResult(key, queryString);
}
/// <summary>
/// Redirects to the Umbraco page with the given id
/// </summary>
/// <param name="publishedContent"></param>
/// <returns></returns>
protected RedirectToUmbracoPageResult RedirectToUmbracoPage(IPublishedContent publishedContent)
{
return new RedirectToUmbracoPageResult(publishedContent, Current.PublishedUrlProvider);
}
/// <summary>
/// Redirects to the Umbraco page with the given id and passes provided querystring
/// </summary>
/// <param name="publishedContent"></param>
/// <param name="queryStringValues"></param>
/// <returns></returns>
protected RedirectToUmbracoPageResult RedirectToUmbracoPage(IPublishedContent publishedContent, NameValueCollection queryStringValues)
{
return new RedirectToUmbracoPageResult(publishedContent, queryStringValues, Current.PublishedUrlProvider);
}
/// <summary>
/// Redirects to the Umbraco page with the given id and passes provided querystring
/// </summary>
/// <param name="publishedContent"></param>
/// <param name="queryString"></param>
/// <returns></returns>
protected RedirectToUmbracoPageResult RedirectToUmbracoPage(IPublishedContent publishedContent, string queryString)
{
return new RedirectToUmbracoPageResult(publishedContent, queryString, Current.PublishedUrlProvider);
}
/// <summary>
/// Redirects to the currently rendered Umbraco page
/// </summary>
/// <returns></returns>
protected RedirectToUmbracoPageResult RedirectToCurrentUmbracoPage()
{
return new RedirectToUmbracoPageResult(CurrentPage, Current.PublishedUrlProvider);
}
/// <summary>
/// Redirects to the currently rendered Umbraco page and passes provided querystring
/// </summary>
/// <param name="queryStringValues"></param>
/// <returns></returns>
protected RedirectToUmbracoPageResult RedirectToCurrentUmbracoPage(NameValueCollection queryStringValues)
{
return new RedirectToUmbracoPageResult(CurrentPage, queryStringValues, Current.PublishedUrlProvider);
}
/// <summary>
/// Redirects to the currently rendered Umbraco page and passes provided querystring
/// </summary>
/// <param name="queryString"></param>
/// <returns></returns>
protected RedirectToUmbracoPageResult RedirectToCurrentUmbracoPage(string queryString)
{
return new RedirectToUmbracoPageResult(CurrentPage, queryString, Current.PublishedUrlProvider);
}
/// <summary>
/// Redirects to the currently rendered Umbraco URL
/// </summary>
/// <returns></returns>
/// <remarks>
/// this is useful if you need to redirect
/// to the current page but the current page is actually a rewritten URL normally done with something like
/// Server.Transfer.
/// </remarks>
protected RedirectToUmbracoUrlResult RedirectToCurrentUmbracoUrl()
{
return new RedirectToUmbracoUrlResult(UmbracoContext);
}
/// <summary>
/// Returns the currently rendered Umbraco page
/// </summary>
/// <returns></returns>
protected UmbracoPageResult CurrentUmbracoPage()
{
return new UmbracoPageResult(ProfilingLogger);
}
/// <summary>
/// Gets the current page.
/// </summary>
protected virtual IPublishedContent CurrentPage
{
get
{
var routeDefAttempt = TryGetRouteDefinitionFromAncestorViewContexts();
if (routeDefAttempt.Success == false)
throw routeDefAttempt.Exception;
var routeDef = routeDefAttempt.Result;
return routeDef.PublishedRequest.PublishedContent;
}
}
/// <summary>
/// we need to recursively find the route definition based on the parent view context
/// </summary>
/// <returns></returns>
/// <remarks>
/// We may have Child Actions within Child actions so we need to recursively look this up.
/// see: http://issues.umbraco.org/issue/U4-1844
/// </remarks>
private Attempt<RouteDefinition> TryGetRouteDefinitionFromAncestorViewContexts()
{
var currentContext = ControllerContext;
while (currentContext != null)
{
var currentRouteData = currentContext.RouteData;
if (currentRouteData.Values.ContainsKey(Core.Constants.Web.UmbracoRouteDefinitionDataToken))
{
return Attempt.Succeed((RouteDefinition)currentRouteData.Values[Core.Constants.Web.UmbracoRouteDefinitionDataToken]);
}
currentContext = currentContext.IsChildAction
? currentContext.ParentActionViewContext
: null;
}
return Attempt<RouteDefinition>.Fail(
new InvalidOperationException("Cannot find the Umbraco route definition in the route values, the request must be made in the context of an Umbraco request"));
}
}
}

View File

@@ -1,140 +0,0 @@
using System;
using System.IO;
using System.Web.Mvc;
using System.Web.Routing;
using Umbraco.Core;
using Umbraco.Core.Logging;
namespace Umbraco.Web.Mvc
{
/// <summary>
/// Used by posted forms to proxy the result to the page in which the current URL matches on
/// </summary>
/// Migrated already to .Net Core
public class UmbracoPageResult : ActionResult
{
private readonly IProfilingLogger _profilingLogger;
public UmbracoPageResult(IProfilingLogger profilingLogger)
{
_profilingLogger = profilingLogger;
}
public override void ExecuteResult(ControllerContext context)
{
ResetRouteData(context.RouteData);
ValidateRouteData(context.RouteData);
var routeDef = (RouteDefinition)context.RouteData.Values[Umbraco.Core.Constants.Web.UmbracoRouteDefinitionDataToken];
var factory = ControllerBuilder.Current.GetControllerFactory();
context.RouteData.Values["action"] = routeDef.ActionName;
ControllerBase controller = null;
try
{
controller = CreateController(context, factory, routeDef);
CopyControllerData(context, controller);
ExecuteControllerAction(context, controller);
}
finally
{
CleanupController(controller, factory);
}
}
/// <summary>
/// Executes the controller action
/// </summary>
private void ExecuteControllerAction(ControllerContext context, IController controller)
{
using (_profilingLogger.TraceDuration<UmbracoPageResult>("Executing Umbraco RouteDefinition controller", "Finished"))
{
controller.Execute(context.RequestContext);
}
}
/// <summary>
/// Since we could be returning the current page from a surface controller posted values in which the routing values are changed, we
/// need to revert these values back to nothing in order for the normal page to render again.
/// </summary>
private static void ResetRouteData(RouteData routeData)
{
routeData.DataTokens["area"] = null;
routeData.DataTokens["Namespaces"] = null;
}
/// <summary>
/// Validate that the current page execution is not being handled by the normal umbraco routing system
/// </summary>
private static void ValidateRouteData(RouteData routeData)
{
if (routeData.Values.ContainsKey(Umbraco.Core.Constants.Web.UmbracoRouteDefinitionDataToken) == false)
{
throw new InvalidOperationException("Can only use " + typeof(UmbracoPageResult).Name +
" in the context of an Http POST when using a SurfaceController form");
}
}
/// <summary>
/// Ensure ModelState, ViewData and TempData is copied across
/// </summary>
private static void CopyControllerData(ControllerContext context, ControllerBase controller)
{
controller.ViewData.ModelState.Merge(context.Controller.ViewData.ModelState);
foreach (var d in context.Controller.ViewData)
controller.ViewData[d.Key] = d.Value;
//We cannot simply merge the temp data because during controller execution it will attempt to 'load' temp data
// but since it has not been saved, there will be nothing to load and it will revert to nothing, so the trick is
// to Save the state of the temp data first then it will automatically be picked up.
// http://issues.umbraco.org/issue/U4-1339
var targetController = controller as Controller;
var sourceController = context.Controller as Controller;
if (targetController != null && sourceController != null)
{
targetController.TempDataProvider = sourceController.TempDataProvider;
targetController.TempData = sourceController.TempData;
targetController.TempData.Save(sourceController.ControllerContext, sourceController.TempDataProvider);
}
}
/// <summary>
/// Creates a controller using the controller factory
/// </summary>
private static ControllerBase CreateController(ControllerContext context, IControllerFactory factory, RouteDefinition routeDef)
{
var controller = factory.CreateController(context.RequestContext, routeDef.ControllerName) as ControllerBase;
if (controller == null)
throw new InvalidOperationException("Could not create controller with name " + routeDef.ControllerName + ".");
return controller;
}
/// <summary>
/// Cleans up the controller by releasing it using the controller factory, and by disposing it.
/// </summary>
private static void CleanupController(IController controller, IControllerFactory factory)
{
if (controller != null)
factory.ReleaseController(controller);
if (controller != null)
controller.DisposeIfDisposable();
}
private class DummyView : IView
{
public void Render(ViewContext viewContext, TextWriter writer)
{
}
}
}
}

View File

@@ -1,40 +0,0 @@
using System.Web.Mvc;
using Umbraco.Core;
using Umbraco.Web.Composing;
namespace Umbraco.Web.Mvc
{
/// <summary>
/// If Umbraco.Core.UseHttps property in web.config is set to true, this filter will redirect any http access to https.
/// </summary>
public class UmbracoRequireHttpsAttribute : RequireHttpsAttribute
{
/// <summary>
/// If Umbraco.Core.UseHttps is true and we have a non-HTTPS request, handle redirect.
/// </summary>
/// <param name="filterContext">Filter context</param>
protected override void HandleNonHttpsRequest(AuthorizationContext filterContext)
{
// If Umbraco.Core.UseHttps is set, let base method handle redirect. Otherwise, we don't care.
if (/*Current.Configs.Global().UseHttps*/ false)
{
base.HandleNonHttpsRequest(filterContext);
}
}
/// <summary>
/// Check to see if HTTPS is currently being used if Umbraco.Core.UseHttps is true.
/// </summary>
/// <param name="filterContext">Filter context</param>
public override void OnAuthorization(AuthorizationContext filterContext)
{
// If umbracoSSL is set, let base method handle checking for HTTPS. Otherwise, we don't care.
if (/*Current.Configs.Global().UseHttps*/ false)
{
base.OnAuthorization(filterContext);
}
}
}
}

View File

@@ -180,10 +180,8 @@
<Compile Include="WebApi\SessionHttpControllerRouteHandler.cs" />
<Compile Include="WebApi\UmbracoApiControllerTypeCollectionBuilder.cs" />
<Compile Include="Runtime\WebInitialComponent.cs" />
<Compile Include="Mvc\UmbracoRequireHttpsAttribute.cs" />
<Compile Include="Mvc\ProfilingView.cs" />
<Compile Include="Mvc\NotFoundHandler.cs" />
<Compile Include="Mvc\RedirectToUmbracoUrlResult.cs" />
<Compile Include="Mvc\UmbracoVirtualNodeByIdRouteHandler.cs" />
<Compile Include="Mvc\EnsurePublishedContentRequestAttribute.cs" />
<Compile Include="Mvc\UmbracoVirtualNodeRouteHandler.cs" />
@@ -216,7 +214,6 @@
<Compile Include="Mvc\MergeModelStateToChildActionAttribute.cs" />
<Compile Include="Mvc\PluginController.cs" />
<Compile Include="Mvc\PostedDataProxyInfo.cs" />
<Compile Include="Mvc\RedirectToUmbracoPageResult.cs" />
<Compile Include="Mvc\Strings.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
@@ -224,7 +221,6 @@
</Compile>
<Compile Include="Mvc\SurfaceController.cs" />
<Compile Include="Mvc\PluginControllerAttribute.cs" />
<Compile Include="Mvc\UmbracoPageResult.cs" />
<Compile Include="RouteCollectionExtensions.cs" />
<Compile Include="UmbracoHelper.cs" />
<Compile Include="Mvc\ViewDataContainerExtensions.cs" />