Connecting To SharePoint Very Slow
-
I have this block of code
try
{
_clientContext = new ClientContext(baseUrl);
_clientContext.Credentials = new SharePointOnlineCredentials(userName, Password.GetSecureString(password));
_clientContext.Load(_clientContext.Web, w => w.ServerRelativeUrl);
_clientContext.ExecuteQuery();
}
catch (Exception e)
{
throw;
}The code stops for about 20-25 seconds on the ExecuteQuery line. If I paste the URL into a browser it loads quicly, so I know that's not the problem. No error is thrown. It's just really slow. All subsequent calls to the server after that are ok. It's on this first calls that is really slow. Can anyone shed some light on this? I'm not really sure how to debug this.
In theory, theory and practice are the same. But in practice, they never are.” If it's not broken, fix it until it is. Everything makes sense in someone's mind.
-
I have this block of code
try
{
_clientContext = new ClientContext(baseUrl);
_clientContext.Credentials = new SharePointOnlineCredentials(userName, Password.GetSecureString(password));
_clientContext.Load(_clientContext.Web, w => w.ServerRelativeUrl);
_clientContext.ExecuteQuery();
}
catch (Exception e)
{
throw;
}The code stops for about 20-25 seconds on the ExecuteQuery line. If I paste the URL into a browser it loads quicly, so I know that's not the problem. No error is thrown. It's just really slow. All subsequent calls to the server after that are ok. It's on this first calls that is really slow. Can anyone shed some light on this? I'm not really sure how to debug this.
In theory, theory and practice are the same. But in practice, they never are.” If it's not broken, fix it until it is. Everything makes sense in someone's mind.
Use Fiddler[^] to check the traffic you are sending out on the first call. My suspicion is that the slow first call is because it's trying to hit the msoid endpoints, which don't exist so you are waiting for the connections to time out. The next call knows that these don't exist so it avoids them. The fix is to change your hosts file to set these connections to your loopback address so that fails straightaway. Fiddler will identify what these domains are for you.