Using Kentico CMS with pre-generated HTML

Clayton Rose asked on February 2, 2021 05:46

I have a huge amount of content that is in pre-generated static html pages. I am working with an organization that runs their web site using Kentico (11) on IIS. They wish to host the pregenerated HTML, but to have a consistent look and feel on the pre-generated pages.

Is there a way to includes tags etc inside the pre-generated html that gets kentico to process the content to give the standard look and feel for the website, without having to convert the content (potentially 100k+ pages) to normal kentico content (it just doesn't seem like a feasible approach, since the content is refreshed from the source regularly)

Recent Answers


Trevor Fayas answered on February 2, 2021 16:25

We may need a little more information:

  1. Are these 100k+ pages of pregenerated HTML currently generated by the Kentico 11 instance? Or they are currently just 'static' and you're trying to add them into the site?
  2. You tagged this as Kentico 13, is this becuase you are looking to rebuild it in Kentico Xperience 13, or was it just a bad tag and you are really doing this all on Kentico 11?
  3. Is the ultimate goal is to still have Pre-generated HTML pages (static site build) but run through Kentico to generate them, or just to import these pre-generated html pages and serve them dynamically through Kentico (no longer pre-generated static html)?
0 votesVote for this answer Mark as a Correct answer

Gaurav Saxena answered on July 22, 2021 10:16 (last edited on July 22, 2021 10:17)

Hi Support team,

My Designer use to generate HTML microsites outside Kentico 13. Now I am looking forward to add these HTML files in Kentico and want to restrict the access of these microsite to specific business. For e.g.

  • Designer has created a microsite for client ABC. So these microsites will be generated as static HTML pages, CSS, JS etc.
  • Now next action is to add these sites in existing Kentico 13 Site (which is blank as of now) by adding a folder in tree structure and we would like to restrict that folder to the specific business.
  • We will create a unique account for that business in Kentico 13.

Similarly in future designer will keep giving micros sites for other business and I have to keep adding them in Kentico 13 (in separate folder under same site) and restrict its access with new user account for specific business users every time.

Please guide how to do that.

Thanks !! Gaurav

0 votesVote for this answer Mark as a Correct answer

Trevor Fayas answered on July 22, 2021 21:26

This is what i would do.

  1. Create a media library for each 'company', put static site files in it
  2. Add a company role and give it access to it's media library
  3. Add user to this role.

Next, we need to check for permissions, any file that is retrieved through the generated media library url (ex '/getmedia/feaf-eaf3-f3q-3aceacea') will automatically check, however for static sites most references are relative and you don't want to go through and update all that.

So, i would create a custom StaticFile OnPrepareResponse to check for the media library and check security: 1. on Startup, when you do app.UseStaticFiles, adjust code to be about this:

app.UseStaticFiles(new StaticFileOptions
        {
            OnPrepareResponse = ctx =>
            {
                if (!ctx.Context.User.Identity.IsAuthenticated)
                {
                    // respond HTTP 401 Unauthorized.
                    ctx.Context.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
                }


                // Cache user and role ID retrieval
                var user = CMS.Membership.UserInfoProvider.GetUserInfo(ctx.Context.User.Identity.Name);
                // get Roles
                var roleIDs = CMS.Membership.UserRoleInfoProvider.GetUserRoles()
                .WhereEquals(nameof(CMS.Membership.UserRoleInfo.UserID), User.UserID)
                .Select(x => x.RoleID);
                // Access denied, All users Authenticated
                string where = "";
                where += " (LibraryAccess < 5000000) AND ((LibraryAccess < 1000000) OR (LibraryAccess > 999999 AND LibraryAccess < 2000000)";

                // Authorized roles
                where += String.Format(" OR (LibraryAccess > 1999999 AND LibraryAccess < 3000000) AND ((SELECT Count(RoleID) FROM Media_LibraryRolePermission WHERE Media_LibraryRolePermission.LibraryID = LibraryID AND PermissionID = (SELECT TOP 1 PermissionID FROM CMS_Permission WHERE PermissionName = 'LibraryAccess') {0}) > 0))", roleIDs);

                // Get library with permission check
                string MediaFileName = ctx.File.PhysicalPath.Trim('/').Split('/')[0];

                // Cache this check, user to media library
                if(CMS.MediaLibrary.MediaLibraryInfoProvider.GetMediaLibraries()
                .WhereEquals(nameof(CMS.MediaLibrary.MediaLibraryInfo.LibraryName), MediaFileName)
                .Where(where)
                .FirstOrDefault() == null)
                {
                    // respond HTTP 401 Unauthorized.
                    ctx.Context.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
                }

            }
            });

I haven't tested this, and you SHOULD cache these methods or extrapolate this logic into an interface or some sort of helper function, but in essence this should check to make sure the current user has access to the requested file's media library (gotten through the path).

0 votesVote for this answer Mark as a Correct answer

Gaurav Saxena answered on July 23, 2021 06:47

Thanks Trevor for quick response and suggestion. Will try it out.

0 votesVote for this answer Mark as a Correct answer

Gaurav Saxena answered on July 23, 2021 17:20

As a first step (without auth) I have uploaded all HTML files along with other assets like CSS, JS etc in Media Libraries created for specific site. When I accessed the HTML page it was not able to pickup the relative path of the assets automatically. I have uploaded the assets in same media library, I am assuming because media libraries use to create own paths with GUID. Is there any way we can refer static path instead of via getmedia?

Also post adding the HTML page in Media libraries (see snapshot), do I need to refer that page somewhere in Pages app so that HTML URL wont be that ugly (see snapshot)?

Sorry if I misunderstood anything above. Note, I ahvewnt worked on security piece as of now. Just want to see how it will go.

0 votesVote for this answer Mark as a Correct answer

Trevor Fayas answered on July 23, 2021 21:25

Ah... You're using azure for storage. That does complicate things as it uses the absolute media url then instead, so no this won't work : /.

You would either have to relink everything to use the media library urls and upload, or use static urls but then you bypass kentico all together so can't set security.

You may indeed be better of creating an html content page type, then somehow try to detect and update urls within the content, or perhaps just recreating the structure entirely in kentico.

0 votesVote for this answer Mark as a Correct answer

Gaurav Saxena answered on July 25, 2021 15:08

I tried creating File page type so that I can upload entire HTML as is which can be rendered smoothly. That works fine in Kentico 10 but didn't find that option in Kentico 13. See this ticket - How to render file attachment content on page: link text

Let me know if you want me to share snapshot for the same.

0 votesVote for this answer Mark as a Correct answer

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