I'm seeing something weird happening in my provider hosted app. When deploying the app via Visual Studio, the output says:
App was installed at https://app-bebd3cad51d715.repsajapps.com/sites/devcenter/Test_PHApp/.
Okay, fine. So now I open up my SharePoint dev site, click on the app and my app is opened. But... the JSOM calls I put in there are failing. I started bugfixing and found out that the URL to my app looks like this:
Let's take a closer look at that SPAppWebUrl querystring parameter and decode it:
Hey... huh... it's a different one as where the app was originally deployed to? When browsing it, SharePoint says:
Cannot find site for request 'https://app-cc98c8ad51d715.repsajapps.com/_login/default.aspx?ReturnUrl=/sites/devcenter/Test_PHApp/_layouts/15/Authenticate.aspx?Source=%252Fsites%252Fdevcenter%252FTest%255FPHApp&Source=/sites/devcenter/Test_PHApp'.
Which seems legit since the app was deployed somewhere else.
So the question now is; why the heck would it include a different URL in the querystring, pointing to a site which does not exist?
Update: from the URL to the app, I got the app instance id. That can be used to retrieve the app instance using Get-SPAppInstance in Powershell. The instance has a AppWebFullUrl property which points to the correct URL (the one from VisualStudio).
Update 2: I removed and rebuilt my developer site, which didn't help. It seems the URL being used for the appweb changed, but it still point to a site which doesn't. I also tried a simple app from the MSDN examples, which behaves exactly the same. I then tried reprovisioning the subscription and app management service applications (removing the databases), which also did not make any difference.