Tuesday, 13 August 2013

Configure Apps


Ok, looked at Output window found another reason.

 " ErrorDetail: Apps are disabled on this site. "

Now we need to remember what we learned in prior post.  Any SharePoint-Hosted App will try to create a Subweb which will be executed in a separate AppDomain apart from SharePoint Farm.
Currently SharePoint dint have any clue on where to Host this app code and what to do with it.

Step 1: We need to create a new App Domain, and register it with SharePoint. So next time when you deploy an App, it know where to host it.
I created my machine on a Domain "Sharepoint13.com". So I would like to create an App Domain "Sharepoint13Apps.com" for hosting purpose. For that go to
Administrative Tools > DNS > following window will b opened showing the Machine Name and the current App Domain in which SharePoint farm is executing.

Right click on Forward Lookup Zone and Click on
"New Zone" > "Next" > "Next" > "Next" > following window will open.

Now the new AppDomain is created, Now we will create a wildcard Alias (CNAME) record to allow apps to create unique domain names within our app domain, Sharepoint13Apps.com. Right-click Sharepoint13Apps.com and select Refresh. Then right-click Sharepoint13Apps.com and select New Alias (CNAME)…
Give the values as I have shown and Click OK.

Now App Domain is created, lets test it now. Open CMD window and try pinging to "abc.Sharepoint13Apps.com". . . Successfully done.

Step 2: We need to register this newly created app domain with SharePoint. Go to Central admin, click on Apps on right menu.
it will give you a message saying

"The Subscription Settings service and corresponding application and proxy needs to be running in order to make changes to these settings. "

This means a new service application running in its own app pool needs to be created and up and running.
Lets create a Managed account with Machine admin credentials. Mine is
"Sharepoint13\Administrator".
Open the PowerShell window and execute below script.

add-pssnapin "Microsoft.Sharepoint.Powershell"

$account = Get-SPManagedAccount sharepoint13\administrator

Remove-SPServiceApplicationPool -Identity SettingsServiceAppPool

$appPoolSubSvc = New-SPServiceApplicationPool -Name SettingsServiceAppPool -Account $account

$appSubSvc = New-SPSubscriptionSettingsServiceApplication -ApplicationPool $appPoolSubSvc -Name SettingsServiceApp -DatabaseName SettingsServiceDB

$proxySubSvc = New-SPSubscriptionSettingsServiceApplicationProxy -ServiceApplication $appSubSvc


It may prompt you once, say Yes.
Some times the above script may give error

"Access denied. Only machine administrators are allowed to create administration service job definitions"
Go to "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\CONFIG\POWERSHELL\Registration" and execute SharePoint.ps1 as Administrator.
Issue will be resolved.

Once this script is successfully executed. We have created a new service Application, and its proxy which will run under its own Service App Pool. To verify this go to
Central Admin > Service Applications > Manage Service Applications > you can see below Svc application created , up and running.
Step 3: Now go to Central Admin > Apps > Configure App URLs

You can see that the new App Domain we created automatically populated here, just mention app prefix as "Apps" and say OK.

We are all set to deploy our SharePoint-Hosted App. Right click on Solution and say "Deploy" 

Once App is deployed successfully, go to SharePoint Application and click on "Site Actions" the little gear symbol on top right and click on Site Content. You can see your App there.

Lastly we have to observe one more thing before closing this topic. Observe the url of site and the url of the App after loading.
We can see SharePoint-Hosted App loaded in different App Domain thus causing no harm to Actual SharePoint Farm in any circumstances.

No comments:

Post a Comment