Jul 15 2020 01:37 AM
Hi there,
The SharePoint Farm: 2* SharePoint WFE + 2* SQL AlwaysOn.
I have a program for accessing the SharePoint Site (https://doc.litwareinc.local).
I got the 401 and 500 Error. After that I access the SharePoint by program and
Does anyone have any idea on it? Thanks
/// OfficeDevPnP
public static ClientContext GetPnPAuthenticatedContext(string siteUrl, string farmAdmin, string password, string domain)
{
/// SharePointPnPCore 2019
/// Sample
try
{
SecureString secureStringPassword = GetSecureString(password);
//Get instance of Authentication Manager
OfficeDevPnP.Core.AuthenticationManager authenticationManager = new OfficeDevPnP.Core.AuthenticationManager();
var clientContext = authenticationManager.GetNetworkCredentialAuthenticatedContext(siteUrl, farmAdmin, secureStringPassword, domain);
Uri uri = new Uri(siteUrl);
if (uri.Scheme == "https")
{
//ServicePointManager.ServerCertificateValidationCallback = delegate (object sender1, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
//{
// bool validationResult = true;
// return validationResult;
//};
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
ServicePointManager.ServerCertificateValidationCallback += new System.Net.Security.RemoteCertificateValidationCallback(customXertificateValidation);
}
//clientContext.Load(clientContext.Web);
//clientContext.Load(clientContext.Site);
clientContext.Load(clientContext.Site.RootWeb);
clientContext.ExecuteQuery();
return clientContext;
}
catch (Exception eX)
{
throw eX;
}
}
/// CSOM
public static ClientContext GetAuthenticatedContext(string siteUrl, string farmAdmin, string password, string domain)
{
ClientContext clientContext = new ClientContext(siteUrl);
clientContext.Credentials = new NetworkCredential(farmAdmin, password, domain);
Uri uri = new Uri(siteUrl);
if (uri.Scheme == "https")
{
//ServicePointManager.ServerCertificateValidationCallback = delegate (object sender1, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
//{
// bool validationResult = true;
// return validationResult;
//};
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
ServicePointManager.ServerCertificateValidationCallback += new System.Net.Security.RemoteCertificateValidationCallback(customXertificateValidation);
}
//clientContext.Load(clientContext.Web);
//clientContext.Load(clientContext.Site);
clientContext.Load(clientContext.Site.RootWeb);
clientContext.ExecuteQuery();
return clientContext;
}