How to open custom aspx page in the browser instead downloading in SharePoint Online?

How to open custom aspx page in the browser instead downloading in SharePoint Online?

No comments

 15,230 total views,  78 views today

Many times we might observe strange behavior in modern SharePoint Online while we upload a custom .aspx file in SharePoint Pages or Site Pages library, and try to open it in the browser – what will happen is, it will be downloading the .aspx file instead of browsing – so, in this article, we will learn about how can we open the aspx page or file in the browser instead of downloading the file?

Solution

In order to fix the above issue or to open the .aspx file in the browser instead of downloading, we need to enable custom scripting in that said site.

Below is the PowerShell script using which we can enable the custom scripting feature in the modern SharePoint Online site.

It is a two steps process, first, we need to enable the custom scripting at the tenant level, then at the site level.

Enable custom scripting at tenant-level through modern admin center UI

Go to your tenant setting page thru this URL

https://sprnd-admin.sharepoint.com/_layouts/15/online/TenantSettings.aspx

Note: Here “sprnd” is my tenant name, you need to pass your tenant name.

Prevent users from running custom script on personal sites in SharePoint Online

Now see the “Custom Script” section by default both the radio button is selected as prevent – this is the default behavior and due to this script editor and content editor web part is missing from SharePoint online page.

  1. Prevent users from running custom script on personal sites.
  2. Prevent users from running custom script on self-service created sites)
Prevent users from running custom script on personal sites in SharePoint Online
Prevent users from running custom script on personal sites in SharePoint Online

 

Now select to allow users to run the custom script for both the radio button as like below:

  1. Allow users from running custom script on personal sites.
  2. Allow users from running custom script on self-service created sites)
Allow users from running custom script on personal sites in SharePoint Online
Allow users from running custom script on personal sites in SharePoint Online

Now click on ok and once you save it, this may take 24 hours to reflect the changes.

How to enable the custom scripting using the PowerShell script?

Execute the below PowerShell script to enable the custom scripting in SharePoint Online (specific site).

$adminUserID="youradminaccount@< sprnd.onmicrosoft.com>"
$userCredential = Get-Credential -UserName $adminUserID -Message "Enter password"
Connect-SPOService -Url https://sprnd-admin.sharepoint.com/ -Credential $userCredential
Set-SPOsite "https://sprnd.sharepoint.com/sites/TestSite001" -DenyAddAndCustomizePages 0

Summary:

Thus, in this article, we have learned about how to enable custom scripting in SharePoint Online specific site and fix the issue of opening a custom aspx page in the browser.

See Also:

You may also like the below SharePoint troubleshooting articles:

Download SharePoint Online & Office 365 Administration eBook

Buy the premium version of SharePoint Online & Office 365 administration eBook from here:



Buy SharePoint Online & Office 365 Administration eBook


 

Get the free demo PDF eBook from here:

FREE DOWNLOAD

Send download link to:

Subscribe to get exclusive content and recommendations every month. You can unsubscribe anytime.