0

Everything was working perfectly and still is, in my local dev environment (VStudio).

I deployed my web app (consists of an Angular 5 front end and a Core 2 backend) using IIS. I wrote both the Angular and the .NET Core side, everything works fine in local env.

The deployment made my api calls to sharepoint stop working. I get a 500 error without any other information. I tested with Postman to make sure the calls are hitting my controllers, and they do, so that's not the issue,

This is my first time working with sharepoint and angular/.NET:

i. How can I deploy on dev mode to see more details in the 500 error?

ii. Is it at all possible that this may be caused by an authentication issue?

Our sharepoint lists require permissions. I am an admin of the site. When I developed locally, I did not code anything for the authorizations, as all api calls were going through just fine - I assume this is because I am logged into a windows laptop, (the SP authorizations are connected with my windows credentials).

But is it possible that on deployment, that doesn't work anymore, and I would have to write a module for getting authorized?

iii. Are there any other gimmicks or reasons why API calls would stop working after deployment?

Any past experience or suggestions are much welcome! I can't put a finger on what is making this happen.

EDIT:

This is an example call:

        ClientContext clientContext = new 
        ClientContext("https://sharepointsite.com 
        Web web = clientContext.Web;
        ListCollection listColl = web.Lists;

        List list = listColl.GetByTitle("Applications");

        //----------------------------------------------------
        //Display Items in List
        //----------------------------------------------------

        CamlQuery query = new CamlQuery();
        query.ViewXml = "<View/>";
        ListItemCollection items = list.GetItems(query);

        clientContext.Load(items);
        if (clientContext.HasPendingRequest)
        {
            clientContext.ExecuteQueryAsync().Wait();
        }
  • Hi, Yousuf. Are you using C# CSOM or JavaScript JSOM? Or REST? Which account is used to run the IIS pool that hosts your app in prod? How are you authenticating? Can you include a sample code before the first API call? – Denis Molodtsov May 22 '18 at 2:30
  • I am using C# CSOM. As I was saying, I did not write anything for the authentication. Is it different for the production environment than the local environment? – Yousuf Jamil May 22 '18 at 13:23
0

If you are using CSOM (C#) you should not have have much issues with the authentication. Just follow these principles:

Basic example:

ClientContext clientContext = new ClientContext(siteUrl);
clientContext.AuthenticationMode = ClientAuthenticationMode.Default;
// Provide credentials to the client context here... See other examples below for some options.
clientContext.Credentials = CredentialCache.DefaultNetworkCredentials;
clientContext.Load(clientContext.Web);
clientContext.ExecuteQuery();
System.Console.ForegroundColor = ConsoleColor.Green;
System.Console.WriteLine($"Connected to the site: {clientContext.Web.Title} | {siteUrl}");
System.Console.ForegroundColor = ConsoleColor.White ;

1) Authenticating against SharePoint Online with user login and password:

ClientContext clientContext = new ClientContext(siteUrl); 
clientContext.AuthenticationMode = ClientAuthenticationMode.Default; 
clientContext.Credentials = new SharePointOnlineCredentials(user, password);

2) Authenticating against SharePoint On-premises with user login and password:

ClientContext clientContext = new ClientContext(siteUrl);
clientContext.AuthenticationMode = ClientAuthenticationMode.Default;
clientContext.Credentials = new NetworkCredential(user, password);

3) Authenticating against SharePoint On-premises with the current user's account:

ClientContext clientContext = new ClientContext(siteUrl);
clientContext.AuthenticationMode = ClientAuthenticationMode.Default;
clientContext.Credentials = CredentialCache.DefaultNetworkCredentials;

Note about #3 If you are running CSOM from a context of an .exe console app then CredentialCache.DefaultNetworkCredentials should refer to the current user's credentials.

If you are running CSOM from a context of a web app (your case), the IIS Application pool's credentials will be used for accessing ClientContext. So make sure this IIS application pool account had enough permissions on the target SharePoint site.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.