2021-02-04 14:51:55 +11:00
|
|
|
using System.Collections.Generic;
|
2021-01-06 20:03:49 +11:00
|
|
|
using System.Threading.Tasks;
|
2020-10-15 11:42:16 +02:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2021-01-06 20:03:49 +11:00
|
|
|
using Microsoft.AspNetCore.Mvc.Filters;
|
2020-10-15 11:42:16 +02:00
|
|
|
using Microsoft.AspNetCore.Mvc.ViewEngines;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
Implements Public Access in netcore (#10137)
* Getting new netcore PublicAccessChecker in place
* Adds full test coverage for PublicAccessChecker
* remove PublicAccessComposer
* adjust namespaces, ensure RoleManager works, separate public access controller, reduce content controller
* Implements the required methods on IMemberManager, removes old migrated code
* Updates routing to be able to re-route, Fixes middleware ordering ensuring endpoints are last, refactors pipeline options, adds public access middleware, ensures public access follows all hops
* adds note
* adds note
* Cleans up ext methods, ensures that members identity is added on both front-end and back ends. updates how UmbracoApplicationBuilder works in that it explicitly starts endpoints at the time of calling.
* Changes name to IUmbracoEndpointBuilder
* adds note
* Fixing tests, fixing error describers so there's 2x one for back office, one for members, fixes TryConvertTo, fixes login redirect
* fixing build
* Fixes keepalive, fixes PublicAccessMiddleware to not throw, updates startup code to be more clear and removes magic that registers middleware.
* adds note
* removes unused filter, fixes build
* fixes WebPath and tests
* Looks up entities in one query
* remove usings
* Fix test, remove stylesheet
* Set status code before we write to response to avoid error
* Ensures that users and members are validated when logging in. Shares more code between users and members.
* Fixes RepositoryCacheKeys to ensure the keys are normalized
* oops didn't mean to commit this
* Fix casing issues with caching, stop boxing value types for all cache operations, stop re-creating string keys in DefaultRepositoryCachePolicy
* bah, far out this keeps getting recommitted. sorry
Co-authored-by: Bjarke Berg <mail@bergmania.dk>
2021-04-20 15:11:45 +10:00
|
|
|
using Umbraco.Cms.Core;
|
2021-02-18 11:06:02 +01:00
|
|
|
using Umbraco.Cms.Core.Models;
|
|
|
|
|
using Umbraco.Cms.Core.Routing;
|
|
|
|
|
using Umbraco.Cms.Core.Web;
|
|
|
|
|
using Umbraco.Cms.Web.Common.ActionsResults;
|
|
|
|
|
using Umbraco.Cms.Web.Common.Filters;
|
2020-10-15 11:42:16 +02:00
|
|
|
|
2021-02-18 11:06:02 +01:00
|
|
|
namespace Umbraco.Cms.Web.Common.Controllers
|
2020-10-15 11:42:16 +02:00
|
|
|
{
|
2021-02-15 18:50:16 +11:00
|
|
|
|
2020-10-15 11:42:16 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// Represents the default front-end rendering controller.
|
|
|
|
|
/// </summary>
|
2020-12-22 10:52:25 +11:00
|
|
|
[ModelBindingException]
|
2021-01-06 20:03:49 +11:00
|
|
|
[PublishedRequestFilter]
|
2021-02-15 18:50:16 +11:00
|
|
|
public class RenderController : UmbracoPageController, IRenderController
|
2020-10-15 11:42:16 +02:00
|
|
|
{
|
2020-12-08 16:33:50 +11:00
|
|
|
private readonly ILogger<RenderController> _logger;
|
2021-01-06 20:03:49 +11:00
|
|
|
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
|
2020-10-15 11:42:16 +02:00
|
|
|
|
2020-12-08 16:33:50 +11:00
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of the <see cref="RenderController"/> class.
|
|
|
|
|
/// </summary>
|
2021-02-17 12:00:57 +01:00
|
|
|
public RenderController(ILogger<RenderController> logger, ICompositeViewEngine compositeViewEngine, IUmbracoContextAccessor umbracoContextAccessor)
|
|
|
|
|
: base(logger, compositeViewEngine)
|
2020-10-15 11:42:16 +02:00
|
|
|
{
|
2021-02-17 12:00:57 +01:00
|
|
|
_logger = logger;
|
2021-01-06 20:03:49 +11:00
|
|
|
_umbracoContextAccessor = umbracoContextAccessor;
|
2020-10-15 11:42:16 +02:00
|
|
|
}
|
|
|
|
|
|
2021-01-06 20:03:49 +11:00
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the umbraco context
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected IUmbracoContext UmbracoContext => _umbracoContextAccessor.UmbracoContext;
|
2020-10-15 11:42:16 +02:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The default action to render the front-end view.
|
|
|
|
|
/// </summary>
|
2020-12-10 18:09:32 +11:00
|
|
|
public virtual IActionResult Index() => CurrentTemplate(new ContentModel(CurrentPage));
|
2021-01-06 20:03:49 +11:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Before the controller executes we will handle redirects and not founds
|
|
|
|
|
/// </summary>
|
|
|
|
|
public override async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
|
|
|
|
|
{
|
|
|
|
|
IPublishedRequest pcr = UmbracoRouteValues.PublishedRequest;
|
|
|
|
|
|
|
|
|
|
_logger.LogDebug(
|
2021-01-08 11:29:07 +11:00
|
|
|
"Response status: Content={Content}, StatusCode={ResponseStatusCode}, Culture={Culture}",
|
|
|
|
|
pcr.PublishedContent?.Id ?? -1,
|
|
|
|
|
pcr.ResponseStatusCode,
|
|
|
|
|
pcr.Culture);
|
2021-01-06 20:03:49 +11:00
|
|
|
|
|
|
|
|
UmbracoRouteResult routeStatus = pcr.GetRouteResult();
|
|
|
|
|
switch (routeStatus)
|
|
|
|
|
{
|
|
|
|
|
case UmbracoRouteResult.Redirect:
|
|
|
|
|
|
|
|
|
|
// set the redirect result and do not call next to short circuit
|
|
|
|
|
context.Result = pcr.IsRedirectPermanent()
|
|
|
|
|
? RedirectPermanent(pcr.RedirectUrl)
|
|
|
|
|
: Redirect(pcr.RedirectUrl);
|
|
|
|
|
break;
|
|
|
|
|
case UmbracoRouteResult.NotFound:
|
|
|
|
|
// set the redirect result and do not call next to short circuit
|
2021-01-08 02:10:13 +11:00
|
|
|
context.Result = GetNoTemplateResult(pcr);
|
2021-01-06 20:03:49 +11:00
|
|
|
break;
|
|
|
|
|
case UmbracoRouteResult.Success:
|
|
|
|
|
default:
|
2021-02-04 14:51:55 +11:00
|
|
|
|
|
|
|
|
// Check if there's a ProxyViewDataFeature in the request.
|
|
|
|
|
// If there it is means that we are proxying/executing this controller
|
|
|
|
|
// from another controller and we need to merge it's ViewData with this one
|
|
|
|
|
// since this one will be empty.
|
|
|
|
|
ProxyViewDataFeature saveViewData = HttpContext.Features.Get<ProxyViewDataFeature>();
|
|
|
|
|
if (saveViewData != null)
|
|
|
|
|
{
|
|
|
|
|
foreach (KeyValuePair<string, object> kv in saveViewData.ViewData)
|
|
|
|
|
{
|
|
|
|
|
ViewData[kv.Key] = kv.Value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-06 20:03:49 +11:00
|
|
|
// continue normally
|
|
|
|
|
await next();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-01-08 02:10:13 +11:00
|
|
|
|
|
|
|
|
private PublishedContentNotFoundResult GetNoTemplateResult(IPublishedRequest pcr)
|
|
|
|
|
{
|
|
|
|
|
// missing template, so we're in a 404 here
|
|
|
|
|
// so the content, if any, is a custom 404 page of some sort
|
|
|
|
|
if (!pcr.HasPublishedContent())
|
|
|
|
|
{
|
|
|
|
|
// means the builder could not find a proper document to handle 404
|
|
|
|
|
return new PublishedContentNotFoundResult(UmbracoContext);
|
|
|
|
|
}
|
|
|
|
|
else if (!pcr.HasTemplate())
|
|
|
|
|
{
|
|
|
|
|
// means the engine could find a proper document, but the document has no template
|
|
|
|
|
// at that point there isn't much we can do
|
|
|
|
|
return new PublishedContentNotFoundResult(
|
|
|
|
|
UmbracoContext,
|
|
|
|
|
"In addition, no template exists to render the custom 404.");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return new PublishedContentNotFoundResult(UmbracoContext);
|
|
|
|
|
}
|
Implements Public Access in netcore (#10137)
* Getting new netcore PublicAccessChecker in place
* Adds full test coverage for PublicAccessChecker
* remove PublicAccessComposer
* adjust namespaces, ensure RoleManager works, separate public access controller, reduce content controller
* Implements the required methods on IMemberManager, removes old migrated code
* Updates routing to be able to re-route, Fixes middleware ordering ensuring endpoints are last, refactors pipeline options, adds public access middleware, ensures public access follows all hops
* adds note
* adds note
* Cleans up ext methods, ensures that members identity is added on both front-end and back ends. updates how UmbracoApplicationBuilder works in that it explicitly starts endpoints at the time of calling.
* Changes name to IUmbracoEndpointBuilder
* adds note
* Fixing tests, fixing error describers so there's 2x one for back office, one for members, fixes TryConvertTo, fixes login redirect
* fixing build
* Fixes keepalive, fixes PublicAccessMiddleware to not throw, updates startup code to be more clear and removes magic that registers middleware.
* adds note
* removes unused filter, fixes build
* fixes WebPath and tests
* Looks up entities in one query
* remove usings
* Fix test, remove stylesheet
* Set status code before we write to response to avoid error
* Ensures that users and members are validated when logging in. Shares more code between users and members.
* Fixes RepositoryCacheKeys to ensure the keys are normalized
* oops didn't mean to commit this
* Fix casing issues with caching, stop boxing value types for all cache operations, stop re-creating string keys in DefaultRepositoryCachePolicy
* bah, far out this keeps getting recommitted. sorry
Co-authored-by: Bjarke Berg <mail@bergmania.dk>
2021-04-20 15:11:45 +10:00
|
|
|
}
|
2020-10-15 11:42:16 +02:00
|
|
|
}
|
|
|
|
|
}
|