Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Dominic Resch 45 posts 115 karma points
    Jul 18, 2024 @ 13:16
    Dominic Resch
    0

    v13: Http-Referer header missing in custom-defined route

    I'm trying to create a breadcrumb based on the previously visited page (it won't work any other way in this case). My problem is that the HTTP Referer header does not exist.

    I create the route like this:

    public class RouteComposer : IComposer
    {
        public void Compose(IUmbracoBuilder builder) =>
            builder.Services.Configure<UmbracoPipelineOptions>(options =>
            {
                AddEndpoint(
                    options,
                    nameof(TopicController),
                    nameof(TopicController.Categories),
                    “/topic/{topic}/{discipline}");
            });
    
        private void AddEndpoint(
            UmbracoPipelineOptions umbracoPipelineOptions,
            string controllerName,
            string actionName,
            string route)
            => umbracoPipelineOptions.AddFilter(new UmbracoPipelineFilter(controllerName)
            {
                Endpoints = app => app.UseEndpoints(endpoints =>
                {
                    endpoints.MapControllerRoute($“{controllerName} - {actionName} Endpoint”, route, new
                    {
                        Controller = controllerName.Replace(“Controller”, “”),
                        Action = actionName
                    }).ForUmbracoPage(FindContent);
                })
            });
    
        private IPublishedContent FindContent(ActionExecutingContext actionExecutingContext)
        {
            IServiceProvider services = actionExecutingContext.HttpContext.RequestServices;
    
            var defaultCultureAccessor = services.GetRequiredService<IDefaultCultureAccessor>();
            var umbracoContextAccessor = services.GetRequiredService<IUmbracoContextAccessor>();
            var variationContextAccessor = services.GetRequiredService<IVariationContextAccessor>();
    
            IUmbracoContext umbracoContext = umbracoContextAccessor.GetRequiredUmbracoContext();
    
            string culture = variationContextAccessor.VariationContext?.Culture ??
                defaultCultureAccessor.DefaultCulture;
    
            return umbracoContext.Content!.GetById(Guid.Parse(“f77e5883-5406-4b1a-9838-1ec9193c0cb3”));
        }
    }
    

    And currently display the referer in my master layout file:

    Referer: @(string.Join(“,”, Context.Request.Headers[“Referer”].ToString()))
    

    This also works so far. Until I open my route, then the referer is suddenly empty.

    However, if I then go from my route to the start page, for example, the referer is displayed again (namely my custom route).

    Can anyone tell me what's going on here?

Please Sign in or register to post replies

Write your reply to:

Draft