Wednesday, 18 February 2015

How to create a provider hosted (high trust) app for sharepoint ?

A Provider Hosted App is a high-trust app for SharePoint. A high trust app uses a digital certificate to establish a trust between remote web application and SharePoint 2013.
You’ll create a .pfx certificate file first, and then a corresponding .cer file.

To create a self-signed .pfx certificate file
1.     Goto the IIS manager, select the ServerName Node in tree view on the left.
Select the Server Certificates option in IIS.
How to create a provider hosted (high trust) app for sharepoint ?
1.      Select the Create Self-Signed Certificate link from the set of links on the right side.
2.      Name the certificate HighTrustSampleCert, and then click Ok.
3.      Right-click the certificate, and then select Export,
4.      Create a folder called C:\Certs.
5.      Back in IIS Manager, export the file to C:\Certs and give it a password.

To create a corresponding .cer file

1.      On the SharePoint server, be sure that the app pool identity for the following IIS app pools have Read rights to the C:\Certs folder:
o    SecurityTokenServiceApplicationPool
o    The app pool that serves the IIS web site that hosts the parent SharePoint web application for your test SharePoint website. For the SharePoint – 80 IIS website, the pool is called OServerPortalAppPool.

2.      In IIS manager, select the ServerName node in the tree view on the left.
3.      Double-click Server Certificates.
4.      In Server Certificates view, double-click HighTrustSampleCert to display the certificate details.
5.      On the Details tab, choose Copy to File to launch the Certificate Export Wizard, and then choose Next.
6.      Use the default value No, do not export the private key, and then choose Next.
7.      Use the default values. Choose Next.
8.      Choose Browse, browse to C:\Certs, name the certificate HighTrustSampleCert, and then choose Save. The certificate is saved as a .cer file.
9.      Choose Next.
10.  Choose Finish.


You have all the required the permissions now. Now you can start the project .
1.      Start Visual Studio 2012 by using the Run as administrator option.

2.      In Visual Studio 2012, on the File menu, choose New, and then choose New Project

3.   In the New Project dialog box, expand the Visual C# node, expand the Office/SharePoint node,           and then choose the Apps node. Choose App for SharePoint 2013.
How to create a provider hosted (high trust) app for sharepoint ?

4.      Name the project, and then choose the OK button.

5.      In the first Specify the App for SharePoint Settings dialog box, name your app and provide the URL of the SharePoint 2013 site that you want to use to debug your app. Under How do you want to host your app for SharePoint, choose Provider-Hosted Choose Finish.

       6. On Selection of provider Hosted, Click Next. The below Screen will be asking the Certificates.  Give the          User certificates, password and Issuer ID and click Finish.The Certificate needs to be created on the                    SharePoint machine and pfx file needs to be exported and shared with the Visual Studio Machine.
How to create a provider hosted (high trust) app for sharepoint ?

1         7.  Now, the Solution has been created.
How to create a provider hosted (high trust) app for sharepoint ?
8.      Solution has 2 projects,
a.      SharepointApp2
b.      SharepointApp2Web
9.      Go to the property of AppWeb project and make the .NET FRAMEWORK4.5 and create a virtual directory will be helpful to host our AppWeb on local IIS .

How to create a provider hosted (high trust) app for sharepoint ?

10.   By clicking Virtual Directory button, Virtual Directory will be created on local IIS.
11.   After property configuration, we are ready with our provided Hosted Application. Rebuild the solution.
12.  Go to the AppManifest.xml in  SharePointApp2 project and set the start page attribute to IIS Directory.

How to create a provider hosted (high trust) app for sharepoint ?
13.      Go to the permission tab. Add the corresponding permission and full control.
14.       Now we will  registered our Client ID with SharePoint, before deploying App. Client ID is nothing but GUID. You can generate the client ID by reaching the APPregnew.aspx inside the 15 hive.
15.       Go to the APPmanifest.xml of SharePointApp2 project and give the client ID.
            <AppPrincipal>
                  <RemoteWebApplication ClientId="*" /
             </AppPrincipal>
4          16. Go to the WebConfig file and add the client ID with below key.

<appSettings>
<add key="ClientId" value="1de402c2-911a-47f5-8b51-fd8b57144c41"/>
<add key="ClientSecret" value="7Q1y02pvvWMBW7fzlAEnHsSGGATFWra1YEFCIo117sg="/>
<add key="ClientSigningCertificatePath" value="C:\MyCertificate.pfx"/>
   <add key="ClientSigningCertificatePassword" value="****"/>
  <add key="IssuerId" value="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx"/>
 </appSettings>

17.Now deploy the Solution. So after successful deployment it will show like a page.

How to create a provider hosted (high trust) app for sharepoint ?
Click the Trust it. The App will get installed. We can lunch the app from our SharePoint Portal. 


No comments:

Post a Comment