The process of building custom applications and tools that interact with Microsoft SharePoint, including SharePoint Online in Microsoft 365.
Thank you for reaching out to Microsoft Community Support and I apologized for any inconveniences cause by this issue.
Based on your description, I understand that you're encountering a problem where .aspx pages are being downloaded instead of displayed in the browser.
This behavior is often due to SharePoint Online’s default security settings. By design, SharePoint Online restricts the use of custom scripts on certain site types—such as self-service created sites or personal sites. If your .aspx pages rely on custom scripting, these restrictions can prevent them from rendering properly, resulting in the browser prompting to download the file instead of displaying it.
Cause: The site collection has the DenyAddAndCustomizePages setting enabled.
To resolve this, please follow the steps below. I’ve also included a picture guide to make the process easier. Some optional method you can try on besides the main methods
**1. Enable Custom Scripting (with Caution) **
Option A: SharePoint Admin Center.
- Go to the SharePoint Admin Center.
- Under Settings, click on Classic Settings Page.
- Scroll down to the Custom Script section.
- Set the following options to Allow users to run custom script on self-service created sites:
Note: This change may take up to 24 hours to take effect.
Option B: Via PowerShell (Immediate Effect) You can enable custom scripting for a specific site collection using PowerShell:
Connect-SPOService -Url https://-admin.sharepoint.com
Set-SPOSite -Identity https://.sharepoint.com/sites/<yoursite> -DenyAddAndCustomizePages 0
Note: Replace <yourtenant> and <yoursite> with your actual tenant and site URL.
**2. Re-upload the .ASPX Page **
After enabling custom scripting:
- Delete the problematic .aspx page.
- Re-upload it is using the “Upload” button in the document library (avoid using drag-and-drop).
**3. OPTIONAL: Change the URL link of the file **
- You can select "Open link in new tab" for the file
- Then choose "Copy link address", open a new browser tab, paste the link and add "?web=1" to the end
Note: This is not the recommended solution, but you can try this to see if the issue persists, your file can be displayed in the browser and not automatically downloaded, if this works, let me know in the replies section
If this response was helpful, please click "Accept Answer" and consider giving it an upvote.
For any follow-up questions, feel free to use the "Comment" option.