How to host static HTML sites on modern SharePoint site collections

SharePoint can be used as a web server to host sites in your organization that are not connected to SharePoint directly, however with the modern experience this is blocked by default.

In this article I’ll explain you how to bring back this awesome functionality to modern Communication and Team sites.

Host static sites modern SharePoint

The hosting of sites in SharePoint will require you to upload all the HTML files with the ASPX extension, however this type of file is blocked and requires custom scripts to be enabled at the tenant level and site collection level.

If you want to learn more about custom scripts before proceeding with the activation have a look to this article.

Enabling custom scripts in modern SharePoint

Before getting custom scripts running on your modern site, you need to make sure it is already enabled at tenant level. To verify or enable it, you should follow these steps:

  1. Open the SharePoint classic admin center by accessing this URL directly (replace contoso by the name of your tenant)
    https://contoso-admin.sharepoint.com/_layouts/15/online/TenantSettings.aspx
  2. Scroll down and locate the Custom Script
  3. Click on Allow users to run custom script on personal sites
  4. Click on Allow users to run custom script on self-service created sites
    Host static sites modern SharePoint
  5. Click OK to save the changes

Note: Changes to the tenant settings can take up to 24 hours to be applied.

In order to enable the custom script in your modern site collection you need to install the latest version of the PnP PowerShell module, more information about how to do it can be found here.

  1. Open the PowerShell console
  2. Execute the following script (replace the URL in the connect by the link of your site collection)
    Connect-PnPOnline -Url https://contoso.sharepoint.com/sites/StaticSite 
    $site = Get-PnPSite 
    Set-PnPSite -Identity $site.URL -NoScriptSite $false
    

Once the execution ends, your modern SharePoint site is ready to host your static HTML site.

Hosting HTML and ASPX files in modern SharePoint

Before uploading the files to SharePoint, you must rename all HTML files to ASPX, your operating system may warn you about changing the file type, but you can proceed without issues.

  1. Choose the location where to store the static HTML site, you can create a new document library or use the Documents library that exists by default in all site collections
  2. Upload all the ASPX files and other related assets like, CSS, JavaScript and Images
  3. Click in the home page of your site

You are ready to navigate and share the link with others inside your organization, in the following animation you can see a static site hosted in SharePoint being displayed in the browser.

Host static sites modern SharePoint


2 Responses to “How to host static HTML sites on modern SharePoint site collections”

  1. Swapna

    April 12, 2022

    Hello, Joao Ferreira

    The approach you explained in this article to host static Sharepoint site/aspx pages by uploading all the files works great for our scenario. I would like to know if there are any known issues we should be aware of if we use this approach. As MS keeps changing the Sharepoint layouts/features/functionalities, we want to make sure we are safe to use this approach.

    Thanks

    Reply
    • João Ferreira

      April 27, 2022

      Hello,

      I don’t see any issue of using this solution other than activating the custom scripts to make it work.
      Even with new features coming to SharePoint they should not impact your static site.

      Have a nice day 🙂

      Reply

Leave a Reply


I've been working with Microsoft Technologies over the last ten years, mainly focused on creating collaboration and productivity solutions that drive the adoption of Microsoft Modern Workplace.