umbraco / Umbraco-CMS

Umbraco is a free and open source .NET content management system helping you deliver delightful digital experiences.
https://umbraco.com
MIT License
4.45k stars 2.68k forks source link

UmbracoContext.PublishedRequest is null, using UmbracoPageController #17217

Open merijng opened 6 days ago

merijng commented 6 days ago

Which Umbraco version are you using? (Please write the exact version, example: 10.1.0)

14.3.0

Bug summary

IUmbracoContextFactory in Umbraco is not functioning as expected in Umbraco versions 14.3.0 and 13.x.x. PublishedRequest is null. This issue does not occur in Umbraco version 12.3.10.

Specifics

Steps to reproduce

Install Umbraco 12.3.10 using:

   dotnet new install Umbraco.Templates::12.3.10
   dotnet new umbraco -n MyProject

Install Umbraco 14.3.0 following the Umbraco documentation.

using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Mvc.ViewEngines;
using Umbraco.Cms.Core.Models.PublishedContent;
using Umbraco.Cms.Core.Web;
using Umbraco.Cms.Web.Common.Controllers;

public class TestController : UmbracoPageController, IVirtualPageController
{
    private readonly IUmbracoContextFactory _umbracoContextFactory;

    public TestController(
        ILogger<UmbracoPageController> logger,
        ICompositeViewEngine compositeViewEngine,
        IUmbracoContextFactory umbracoContextFactory)
        : base(logger, compositeViewEngine)
    {
        _umbracoContextFactory = umbracoContextFactory;
    }

    public IPublishedContent FindContent(ActionExecutingContext actionExecutingContext)
    {
        using (var reference = _umbracoContextFactory.EnsureUmbracoContext())
        {
            if (reference.UmbracoContext.PublishedRequest == null)
                throw new Exception("Test failed");
            else
                throw new Exception("Test passed");
        }
    }

    [HttpGet]
    public async Task<IActionResult> Index(string id = null)
    {
        throw new Exception("Test passed");
    }
}
u.EndpointRouteBuilder.MapControllerRoute(
   nameof(TestController),
   "/test/{id?}",
   new { Controller = "Test", Action = "Index" });

Expected result / actual result

github-actions[bot] commented 6 days ago

Hi there @merijng!

Firstly, a big thank you for raising this issue. Every piece of feedback we receive helps us to make Umbraco better.

We really appreciate your patience while we wait for our team to have a look at this but we wanted to let you know that we see this and share with you the plan for what comes next.

We wish we could work with everyone directly and assess your issue immediately but we're in the fortunate position of having lots of contributions to work with and only a few humans who are able to do it. We are making progress though and in the meantime, we will keep you in the loop and let you know when we have any questions.

Thanks, from your friendly Umbraco GitHub bot :robot: :slightly_smiling_face:

merijng commented 6 days ago

Maybe related to #16426 and/or #12834?