Azure blob storage - kentico website project

Naresh Ede asked on March 13, 2020 18:09

Hello All,

I have a website with two environments (in azure app services).

  1. Main site in production slot
  2. Test site in another slot in same app service

Also I have a storage account, containg two blob containers( Prod & Test).

In my app code module class, I am using the CustomRootPath different for both environments. Below is for my Prod site and

protected override void OnInit()
    {
        base.OnInit();
        // Creates a new StorageProvider instance
        var mediaProvider = new StorageProvider("Azure", "CMS.AzureStorage");

        // Specifies the target container
        mediaProvider.CustomRootPath = "Prod";

        // Makes the container publicly accessible
        mediaProvider.PublicExternalFolderObject = true;

        // Maps a directory to the provider        
        StorageHelper.MapStoragePath("~/mysite/files/", mediaProvider);        
    }

Below is for my test site

protected override void OnInit()
    {
        base.OnInit();
        // Creates a new StorageProvider instance
        var mediaProvider = new StorageProvider("Azure", "CMS.AzureStorage");

        // Specifies the target container
        mediaProvider.CustomRootPath = "Test";

        // Makes the container publicly accessible
        mediaProvider.PublicExternalFolderObject = true;

        // Maps a directory to the provider        
        StorageHelper.MapStoragePath("~/mysite/files/", mediaProvider);        
    }

All the attachments in Prod site are working fine using kentico urls, but not working with Test site urls.

Both the blob containers having the same data.

I am accessing the attachment/media using the below URL formats

https://prodsite.com/CMSPages/GetFile.aspx?guid=487cb5d3-2d00-4197-b4e3-e321599ab6cd

https://testsite.com/CMSPages/GetFile.aspx?guid=487cb5d3-2d00-4197-b4e3-e321599ab6cd

The first URL is working fine but the second URL is getting the message "The resource you are looking for has been removed, had its name changed, or is temporarily unavailable."

Please help me to resolve the above issue.

Thanks!

Recent Answers


Peter Mogilnitski answered on March 13, 2020 20:17

Well it probably something in your settings. Compare settings from (prod and test ) Run select KeyName, KeyValue from CMS_SettingsKey on both DB to find what is the difference.

0 votesVote for this answer Mark as a Correct answer

Brian McKeiver answered on March 14, 2020 16:48

Make sure your app code module class is being initialized and run correctly in the Test site. I'add an an event log call right after you new up the StorageProvider and watch the event log on an App_start event to make sure the Test site is correctly registering the custom class.

I'd also make sure your test code base has the assembly marked as discoverable:

using CMS;
[assembly: AssemblyDiscoverable]

If it is still not there, make sure that file is acutally in the Blog Storage container with that GUID in the Media Library using Azure Store Explorer. (Once you make the change to add external storage provider via Azure Blob, it only works for going forward (new files) it doesnt move old ones that may have been only in the Azure App Service's filesystem.

My blog post has the full walk through as well: https://www.mcbeev.com/Blog/November-2018/Configure-Kentico-MVC-Sites-for-Azure-Blob-Storage-with-Media-Libraries

0 votesVote for this answer Mark as a Correct answer

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