Copied to clipboard

Flag this post as spam?

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


  • Andreas Kristensen 65 posts 269 karma points c-trib
    Sep 05, 2023 @ 06:18
    Andreas Kristensen
    0

    Presence of SEO Checker cancels middleware execution

    If you have a simple piece of custom middleware installed on the same website as SEO Checker, the presence of SEO Checker will cancel the execution of that middleware.

    If you add a custom piece of middleware like this, to the app.UseUmbraco().WithMiddleware(...) part of Startup.cs, the middleware will not be executed when visiting a frontend page of the website. It will however be executed when visiting the backoffice. enter image description here

    class TrackingContentMiddleware
        {
            private readonly RequestDelegate _next;
    
            public TrackingContentMiddleware(RequestDelegate next)
            {
                _next = next;
            }
    
            public async Task InvokeAsync(HttpContext context)
            {
                IUmbracoContextFactory umbracoContextFactory = context.RequestServices.GetRequiredService<IUmbracoContextFactory>();
    
                using (UmbracoContextReference umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext())
                {
                    IPublishedContent? content = umbracoContextReference.UmbracoContext?.PublishedRequest?.PublishedContent;
                    //Add tracking stuff here
    
                }
    
                await _next.Invoke(context);
            }
        }
    

    If you then go ahead and remove SEO Checker from the website, the middleware will be executed on every frontend page visit.

    Turning on/off rewrites and/or redirects in SEO Checker does not make a difference.

    Moving the middleware outside of the app.UseUmbraco().WithMiddleware(...) will make it execute, but that is not where it's supposed to be, and won't make the middleware work as expected.

    Note: The middleware in this post is an example.

    Solution is running: Umbraco CMS 10.4.2 and SEO Checker 10.0.4.

  • Andreas Kristensen 65 posts 269 karma points c-trib
    Sep 06, 2023 @ 09:04
    Andreas Kristensen
    0

    This seems like a bug in the Umbraco 10 version of SEO Checker.

    I did the same test on a site running Umbraco 12.1.1 and SEO Checker 12.0.0 and the middleware is acting as expected.

Please Sign in or register to post replies

Write your reply to:

Draft