I get error 401 (or 403) when trying to connect to Project Online with CSOM in a console app. (This is not on-premise. It is Microsoft Project Online 2013.) Here is the code.
ProjectContext projContext = new ProjectContext(pwaPath);
projContext.Credentials = new NetworkCredential("myUserID", "mypwd", "xxx.onmicrosoft.com");
projContext.ExecutingWebRequest += new EventHandler<WebRequestEventArgs>(projContext_ExecutingWebRequest);
projContext.Load(projContext.Projects);
projContext.ExecuteQuery();
**// Error 401 Unauthorized**
static void projContext_ExecutingWebRequest(object sender, WebRequestEventArgs e)
{
e.WebRequestExecutor.WebRequest.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f");
}
And another try, without ExecutingWebRequest:
ProjectContext projContext = new ProjectContext(pwaPath);
projContext.Credentials = new NetworkCredential("myUserID", "mypwd", "xxx.onmicrosoft.com");
projContext.Load(projContext.Projects);
projContext.ExecuteQuery();
**// Error 403 Forbidden**
Q1: Are there any problems with the code?
Q2: Is there a setting in Project Online that I'm missing?
You can use:
instead of
First: Install required Client SDK
Second: add the reference to your project
You can find the dlls in
%programfiles%\Common Files\microsoft shared\Web Server Extensions\15\ISAPI
and%programfiles(x86)%\Microsoft SDKs\Project 2013\REDIST
Here is sample code:
I already answered this question in other question How to authenticate to Project Online PSI services?