Azure blob permanent media URLs not working in MVC app on 12 to 13 upgrade

Stephen Rushing asked on May 13, 2023 18:06

I'm in the process of upgrading a site from 12 to 13 (ASP.Net Framework). I'm on the latest hotfix 13.0.110.

I have a CustomAzureStorage module in a class library project that has been working successfully for the v12 site.

The media library works normally in the Admin area (upload and image previews are working).

The frontend is using permanent /getmedia URLs at. I've verified that the module OnInit is running in the MVC front-end, which is the same project that's mapping the directories for the Admin (and has been working prior to the upgrade).

Content-tree based routing and system routes for PageBuilder are working.

Recent Answers


Juraj Ondrus answered on May 14, 2023 07:55

Was the admin app launched after the upgrade and prior applying hotfix? Were the Upgrade Start and Finish events logged in the Event Log?
Were also the NuGet packages in the front end app updated to match the admin app hotfix version? What does it mean "not working"? What errors are you getting?
Have you tried re-signing macros?
When you upload new file to the media library and link it in the content - does it work? To see whether also new files are affected or only existing ones.

0 votesVote for this answer Mark as a Correct answer

Stephen Rushing answered on May 15, 2023 01:39

Was the admin app launched after the upgrade and prior applying hotfix?

Yes

Were the Upgrade Start and Finish events logged in the Event Log?

Yes

Were also the NuGet packages in the front end app updated to match the admin app hotfix version?

Yes

What does it mean "not working"? What errors are you getting?

404s on the images.

Have you tried re-signing macros?

Just did - no change.

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on May 15, 2023 06:40

When you add the same storage provider project to the sample Dancing Goat project, I mean out of the box Kentico installation, does it work or not? I just tested it and the blob storage works fine. What is your storage provider code like? Are you mapping the right folder? What is set as the media libraries folder for your site in the Settings app?

0 votesVote for this answer Mark as a Correct answer

Stephen Rushing answered on May 15, 2023 18:04 (last edited on May 15, 2023 18:15)

Uploading a new image to the media library works within the admin section (the media library preview works and it is in the azure container), but not in page preview/front-end.

The media library settings are the defaults, so [sitename]/media.

The mapping code maps all site folders and was working before the upgrade. Given that it's also working in the admin, this makes me think it's a routing issue.

Here's the mapping module code.

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on May 16, 2023 10:21

Thanks for the details. I am unable to reproduce the issue but maybe the hint that you are mapping all the project folders was the right one. I am wondering that it worked previously, maybe it was luck or maybe you took advantage of some bug which was fixed in Kentico 13. If both apps are using the same storage, then you should configure the shared storage. Or, another mention in the docs here. It seems to me that the web farm sync could be confused when multiple apps are looking into the same location - but in this case, there should not be done any sync if it is one and the same file for all the apps.

0 votesVote for this answer Mark as a Correct answer

Stephen Rushing answered on May 16, 2023 17:03 (last edited on May 16, 2023 17:36)

I'm not sure how mapping the media files of each site to their respective folders in Azure blob would be a problem, as it's just a dynamic way of specifying each site. They're all still in their own separate folders, and I can see the correct mapped paths logged from the OnInit code. Did you take a look at the mapping code link - do you see any issues with that?

A major source of confusion for me is that it's also working in the admin, so there's no real file to push in a web farm task. Shouldn't the Azure blob mapping pull files as needed into the App_Data folder as it was before the upgrade?

Given this setup with blob storage, I also don't think shared storage is applicable, or am I misunderstanding?

Here's a full copy of the 404 output. It doesn't even look like the route is being processed by the appropriate handler.

HTTP Error 404.0 - Not Found
The resource you are looking for has been removed, had its name changed, or is temporarily  unavailable.

Most likely causes:
The directory or file specified does not exist on the Web server.
The URL contains a typographical error.
A custom filter or module, such as URLScan, restricts access to the file.

Things you can try:
Create the content on the Web server.
Review the browser URL.
Create a tracing rule to track failed requests for this HTTP status code and see which module is calling SetStatus. For more information about creating a tracing rule for failed requests, click here.

Detailed Error Information:
Module     ManagedPipelineHandler
Notification       ExecuteRequestHandler
Handler    CMS.AspNet.Platform.Routing.ReadOnlySessionActionResultHttpHandler
Error Code     0x00000000
Requested URL      http://lummus:80/getmedia/91c35263-d4cb-4ef9-9abe-8d44fe399aca/innovaion-blue-2.jpg
Physical Path      C:\Users\steph\Workspaces\Lummus_MVC\Lummus\getmedia\91c35263-d4cb-4ef9-9abe-8d44fe399aca\innovaion-blue-2.jpg
Logon Method       Anonymous
Logon User     Anonymous

Is there some extension method I need to run for file routing like UsePageRouting? Here's a copy of my RouteConfig.cs. I do have runAllManagedModulesForAllRequests enabled in the web.config.

using System.Web.Mvc;
using System.Web.Routing;
using Kentico.Web.Mvc;

namespace Lummus
{
    public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            // route for sitemap
            routes.MapRoute(
               name: "Sitemap",
               url: "sitemap.xml",
               defaults: new { controller = "Sitemap", action = "Index" }
           );

            // route for robots
            routes.MapRoute(
                name: "Robots",
                url: "robots.txt",
                defaults: new { controller = "Robots", action = "Index" }
            );

            // route for manifest.json
            routes.MapRoute(
                name: "Manifest",
                url: "manifest.json",
                defaults: new { controller = "Manifest", action = "Index" }
            );

            // Map routes to Kentico HTTP handlers first as some Kentico URLs might be matched by the default ASP.NET MVC route resulting in displaying pages without images
            routes.Kentico().MapRoutes();

            // This will honor Attribute Routing in MVC [Route("")] and [RoutePrefix("")] over Dynamic Routing
            //<see href="https://devblogs.microsoft.com/aspnet/attribute-routing-in-asp-net-mvc-5/">See Attribute Routing</see>
            routes.MapMvcAttributeRoutes();

            // Redirect to administration site if the path is "admin"
            // Can also replace this with the [Route("Admin")] on your AdminRedirectController's Index Method
            routes.MapRoute(
                name: "Admin",
                url: "admin",
                defaults: new { controller = "AdminRedirect", action = "Index" }
            );

            // This will again look for matching routes or node alias paths, this time it won't care if the route is priority or not.
            routes.MapRoute(
                 name: "Default",
                 url: "{controller}/{action}/{id}",
                 defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
        }
    }
}

I also did the failed request tracing (logged here), and I do see CMSGetMedia in there, but it looks like it might be passing it off? Not familiar with reading these logs.

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on May 17, 2023 08:58

I tried using your code in my Kentico 13 instance with multiple Dancing Goat MVC projects and I am unable to reproduce the issue. In your code there are some obsolete methods used but it works fine. What is the code to work with media files in your front end app? Have you adjusted the code to reflect the API changed? Are you using this?

0 votesVote for this answer Mark as a Correct answer

Stephen Rushing answered on May 17, 2023 16:49

These are stored as permanent media URL via the URL Selector field type, so there's no usage of the IMediaFileUrlRetriever in the MVC app, if that's what you mean.

The URL format is correct according to those docs though, .e.g https://localhost/getmedia/ef2a361b-cf86-4150-9ee0-e63535f99406/lab_gloves.jpg

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.