title: C# Sharepoint 365 online returns "unauthorized"
body: <p>I am trying to connect to a Sharepoint site which I can open &amp; navigate in a browser, so I do have permissions. But in my .NET Framework 4.7.2 Console app, I am getting &quot;401 unauthorized&quot;. What am I missing? I am using the &quot;Microsoft.SharePoint.Client.Online.CSOM&quot; nuget package, not sure if that's the right one, but only there I had the &quot;SharePointOnlineCredentials&quot; which other posts recommend to use.</p>
  <pre><code>var siteUrl = &quot;https://mycompany.sharepoint.com&quot;;
  var context = new ClientContext(siteUrl);
  var securePassword = new NetworkCredential(&quot;&quot;, &quot;mypw&quot;).SecurePassword;
  context.Credentials = new SharePointOnlineCredentials(&quot;myusername@mydomain&quot;, securePassword);
  var web = context.Web;
  
  context.Load(web);
  context.ExecuteQuery(); // 401 UNAUTHORIZED
  </code></pre>
  <p>When I am using the &quot;Microsoft.SharePointOnline.CSOM&quot; package instead, I am getting this error:</p>
  <p>&quot;Cannot contact web site 'https://mycompany.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+denied.+Before+opening+files+in+this+location%2c+you+must+first+browse+to+the+web+site+and+select+the+option+to+login+automatically&quot;</p>
  <p>Until now, I couldn't find anything that helped.</p>
  <p>Do I need to register the app in Azure AD or is that only needed for .NET Standard?</p>