Quantcast
Channel: Developing Apps for SharePoint 2013 forum
Viewing all articles
Browse latest Browse all 8089

Provider Hosted Web Forms BoilerPlate Code doesn't work VS2013?

$
0
0

Hi,

I'm struggling to achieve seemingly the most basic thing here and could do with some help getting started....

I have :-

- A SharePoint Online Tenancy with a Dev Site

- Visual Studio 2013

I'm firing up VS2013 and creating a new project - App For SharePoint - which I set to "Provider Hosted" using ACS ... and of type "Web Forms" (rather than MVC).

I set my developer site to that of the one in my tenancy and authenticate to login.

Using the boilerplate code that is generated, I hit F5 and get an immediate fail in the code-behind of the Page_Load on Default.aspx

Object reference not set to an instance of an object ... and the line that fails is the :-

clientContext.Load(clientContext.Web, web => web.Title);

For some reason, clientContext is returned as a NULL from spContext.CreateUserClientContextForSPHost())

Here's the entirety of the code :

 protected void Page_Load(object sender, EventArgs e)
        {
            // The following code gets the client context and Title property by using TokenHelper.
            // To access other properties, the app may need to request permissions on the host web.
            var spContext = SharePointContextProvider.Current.GetSharePointContext(Context);

            using (var clientContext = spContext.CreateUserClientContextForSPHost())
            {
                    clientContext.Load(clientContext.Web, web => web.Title);
                    clientContext.ExecuteQuery();
                    Response.Write(clientContext.Web.Title);
            }
        }

spContext itself seems to be ok .... but clearly there's an issue with the usertoken.

I've tried modifying the appmanifest to grant permissions to the web ... but it just won't play ball.

Am I missing something fundamentally basic here to be able to debug and run in dev mode ??

I've even gone into the AppRegNew.aspx page in my dev site to register my app and obtain my client id and client secret which I've added to the web.config of my remote app (and the client id into the app manifest) ... but no joy ...



Viewing all articles
Browse latest Browse all 8089

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>