1

I have created a high-trust SharePoint 2013 Add-in project to access my SharePoint server folders. It uses a self-signed certificate for the authentication purpose. My SharePoint server and SharePoint add-in, the project is running in the same machine.

My goal is to access the sharepoint add-in services from another project like API.

So I achieved this by adding a WebAPI NuGet packages to my sharepoint add-in project. I can successfully call the API methods in the add-in project. But the issue is when I try to call sharepoint context, HttpContext becomes null and it requires "Controller" instead of "ApiController". The code is as below

public class SPController : ApiController
    {
        public IEnumerable<string> Get()
        {
            var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext);
            var clientContext = spContext.CreateUserClientContextForSPHost();

            return new string[] { "Success" };
        }
    }

I searched a lot to find the solution but nothing works. How can I fix this issue? Is there any other workaround availabel to access the sharepoint add-in services from another project like API? If so, please share the links.

Your Answer

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

Browse other questions tagged or ask your own question.