In this SharePoint Online tutorial, we will discuss, how to fix the error, cannot contact web site or the web site does not support sharepoint online credentials.
The web site does not support sharepoint online credentials
Recently while working with CSOM in SharePoint Online by using the SharePointPnPCoreOnline.dll, I got the error, Cannot contact web site ‘https://tsinfotechnologies.sharepoint.com/’ or the web site does not support SharePoint Online credentials. The response status code is ‘Unauthorized’. The response headers are ‘X-SharePointHealthScore=0, X-MSDAVEXT_Error=917656; Access.
The error looks like below:
I just wrote a simple CSOM code to get the website title like below:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OfficeDevPnP.Core.Entities;
using Microsoft.SharePoint.Client;
using System.Configuration;
namespace conrosdemo
{
class Program
{
static void Main(string[] args)
{
OfficeDevPnP.Core.AuthenticationManager authMgr = new OfficeDevPnP.Core.AuthenticationManager();
string PWD = ConfigurationManager.AppSettings["PWD"];
string siteURL = "https://tsinfotechnologies.sharepoint.com/sites/enjoysharepoint";
string userName = "[email protected]";
using (var ctx = authMgr.GetSharePointOnlineAuthenticatedContextTenant(siteURL, userName, PWD))
{
ctx.Load(ctx.Web);
ctx.ExecuteQuery();
string s= ctx.Web.Title;
}
}
}
}
The above error was coming on the below line:
ctx.ExecuteQuery();
Here, the username and password were correct, still, the error “the web site does not support sharepoint online credentials” was coming.
The same error can also come in PowerShell.
c# the web site does not support sharepoint online credentials – Fix
To fix the error, cannot contact web site or the web site does not support sharepoint online credentials, follow the below steps:
- Open SharePoint Online admin center (https://tsinfotechnologies-admin.sharepoint.com/)
- This click on Policies -> Access control. Here we need to verify two options on Unmanaged devices and Apps that don’t use modern authentication.
- First, click on Unmanaged devices and Here make sure, Allow full access from desktop apps, mobile apps and the web option is selected like below:
- Then click on Apps that don’t use modern authentication and make sure, Allow access option is selected there.
After enabling the above two options, when you run the C# CSOM code, the error will not appear. It will execute successfully.
PowerShell
We can also use Microsoft PowerShell to enable or disable the above options.
Open SharePoint Online management shell, then run the below commands.
Connect-SPOService
Set-SPOTenant -LegacyAuthProtocolsEnabled $True
Set-SPOTenant -RequireAcceptingAccountMatchInvitedAccount $False
Note: It may take up to 30 minutes to reflect the changes.
Check out the below posts:
- How to Authorize users to access GRAPH APIs with OAuth 2.0
- How to customize a SharePoint List form
- SharePoint create folder programmatically using CSOM
- Content type Examples using CSOM in SharePoint
- How to activate SharePoint Publishing Feature Programmatically using CSOM and PowerShell
This is how to fix the error, cannot contact web site or the web site does not support sharepoint online credentials.
After working for more than 15 years in Microsoft technologies like SharePoint, Office 365, and Power Platform (Power Apps, Power Automate, and Power BI), I thought will share my SharePoint expertise knowledge with the world. Our audiences are from the United States, Canada, the United Kingdom, Australia, New Zealand, etc. For my expertise knowledge and SharePoint tutorials, Microsoft has been awarded a Microsoft SharePoint MVP (9 times). I have also worked in companies like HP, TCS, KPIT, etc.
Honestly, this doesn’t appear to be a valid solution in a productive environment, if you don’t want to have intruders.