SharePoint Pals
 | Sign In
How to create a Provider Hosted Application on Form Based Authentication WebApplication in SharePoint 2013
by Sathish Nadarajan 8 Jun 2015
SharePoint MVP
Today  :   1     Total  :    9667

In these previous articles, PHA and FBA, we saw how to create a Provider Hosted Application and How to make a Web Application as Form Based Authentication in SharePoint 2013. In this article, now, let us see how to integrate both of them. i.e., A Provider Hosted App which retrieves the Client Context of a SharePoint Web Application which is a Form Based Authentication using Visual Studio 2013.

One important thing we need to identify here is, there is a new class called SharePointContext.cs has been introduced by Microsoft with Visual Studio 2013, which is not there in Visual Studio 2012. Please find the reference here.

With that information, the rest of the steps are same as that of an ordinary Provider Hosted Application. Refer here

Everytime, I discuss about PHA, I am considering only the High Trust Apps. We had seen enough information about those in the past articles. Hence, I am targeting only, how to convert our AppWeb into Form Based Authentication, so that it can fetch the Client Context without any issues. Once, we fetch the client context, then the remaining things will be very smooth I guess.

To convert the Appweb as Form Based Authentication, there is nothing much. Only modifying the AppWeb’s web.config will do the magic. The sample web.config file is as follows. I request the readers to modify their web.config with appropriate values from their environment.

The sample web.config will be as below.

 <?xml version="1.0" encoding="utf-8"?>
   For more information on how to configure your ASP.NET application, please visit
     <compilation debug="true" targetFramework="4.5" />
     <httpRuntime targetFramework="4.5" />
       <deny users="?" />
         <authentication mode="Forms" />
     <add key="ClientId" value="7c6413ef-3c84-4f04-8912-b7b2c7e43ef9" />
     <add key="ClientSigningCertificatePath" value="C:\SATHISH\Certificates\PHACertificate.pfx" />
     <add key="ClientSigningCertificatePassword" value="Password11" />
     <add key="IssuerId" value="928a1244-8b2e-4d93-9e09-5c72445d15ca" />
         <!--Used by app for SharePoint-->
         <binding name="secureBinding">
           <security mode="Transport" />
       <add binding="basicHttpBinding" scheme="https" bindingConfiguration="secureBinding" />
         <directoryBrowse enabled="true" />

Then on the Default.aspx.cs, let us try to get the ClientContext.

 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())

We can see a difference here. That is till Visual Studio 2012 Era, we used the TokenHelper.cs directly to get the ClientContext. But now in Visual Studio 2013, we can get the ClientContext by means of a new Class called SharePointContext.CS. I have mentioned a link earlier in this article, which describes about the SharePointContext.cs in detail.

Hope this is very easy right..

Download the Sample Config Files Here

Happy Coding,

Sathish Nadarajan.

blog comments powered by Disqus

SharePoint Pals

SharePoint Pals, a community portal for SharePoint developers, Administrators and End Users. Let's join hands and share the point together.
Read this on mobile


Angular Js Training In Chennai
Advanced Angular Js training with real world developer scenarios
Angular Js, Web Api and Ionic for .Net Developers
All in one client side application development for .Net developers
Angular Js For SharePoint Developers
Get ready for the future. Its no more just C#

Get Connected

SharePoint Resources

SharePoint 2013 and 2010 Web Parts
Free Web Parts with Source Code for SharePoint Community

SharePoint 2013 Books and Tutorials
Collection of free SharePoint 2013 books and tutorials (eBooks, pdfs)

Supported By

Contribute your article and be eligible for a one month Free Subscription for Plural Sight. The Author of the most popular New Article (published in the previous month) will be awarded with a Free One month Plural Sight Subscription. Article can be sent to in a word document.

Related Resources

Recent Tweets

Twitter January 15, 00:25
How To Enable Target Value And Actual Value In #D3 Gauge Chart

Twitter January 15, 00:24
How To Open #SharePoint List Hyperlink Column In Modal #Popup Window

Twitter January 15, 00:24
Quick Introduction To #Asp.NetCore And It’s Features

Twitter January 15, 00:22
How To Configure #PerformancePoint Services To Use Secure Store In #SharePoint 2013

Twitter January 15, 00:21
How To Block Or Disable #Office365 Services

Follow us @SharePointPals
Note: For Customization and Configuration, CheckOutRecent Tweets Documentation