Saturday, 24 October 2015

HOW TO CONFIGURE DNS AND SSL FOR SHAREPOINT 2013 APPS

One of the greatest additions that was introduced in SharePoint 2013 is the app model. This allows for stand-alone apps that add additional functionality to SharePoint. They can be hosted in a SharePoint environment or hosted completely outside of SharePoint by the provider themselves.

Configuring SharePoint 2013 to use apps is actually fairly straightforward and easy. Microsoft has documented most of it in their Technet blog. However, two of the most common questions I’ve been asked are due to confusion around the DNS configuration and how to actually apply the SSL for apps.
Part of this confusion is centered on how Microsoft recommends configuring DNS and how most admins are used to applying SSL certificates. Yes, these two issues are related, so if you came here wondering how to apply your app domain’s SSL, then you may have already run into an issue like this with your SSL secured SharePoint site:
SSL secured SharePoint site
So, today I’m going to talk through the DNS and SSL configuration for SharePoint 2013 apps.(If your site isn’t using SSL, then you could skip that part I guess, but why not stay along for the ride anyways?)

Part 1: DNS Configuration

Step 1: You will need to acquire an app domain.
It is strongly recommended that this domain is separate from your site’s domain. For example:
Example Site = mytestsite.onfpweb.net
Example App domain = onfpwebapps.net (completely separate from onfpweb.net)
Step 2: Configure DNS for both the site and the app domain.
So first, let’s talk about what the URL of an app would be.
Whenever a new app is added into SharePoint, it will be given a unique name with the app prefix and an app ID. In my example, it would look something like app-7422a132061cd3.onfpwebapps.netSo each app will have a URL that will be a unique sub-domain of your chosen app domain. It would become a little monotonous to keep adding new ‘A’ records in DNS for each app that you add. This is why we’ll be configuring the wildcard CNAME record in step 2c below:
  • Note: If you want to test the app store locally on your server then you’ll need to configure DNS in your SharePoint environment’s domain’s DNS.
  • Note: If your users will be using public DNS to access the site, then the following DNS records would need to be created on your public DNS servers for your site and your app domain as well.
Below is an example of the DNS configuration in my test server’s DNS settings using internal IP’s. Obviously for public DNS, I would be using the external IP’s instead.
2a. If they are not already created, then create two new Forward Lookup Zones for your site and app domain:
Forward lookup zones for your site
2b. Create an ‘A’ record for your SharePoint site. (It is “mytestsite.onfpweb.net” in my example):
Create an ‘A’ record for your SharePoint site
2c. Create a wildcard CNAME record for your app domain that points to your site URL
Create a wildcard CNAME record for your app domain
points to my site’s Fully Qualified Domain Name
(In my example, the wildcard record for my app domain, “*.onfpwebapps.net” points to my site’s Fully Qualified Domain Name “mytestsite.onfpweb.net”.)
What the wildcard CNAME record is doing is directing any traffic that goes tosomerandomurl.onfpwebapps.net (app domain) towards mytestsite.onfpweb.net (the SharePoint site’s FQDN):
wildcard CNAME record directs traffic

Part 2: Configuring SSL

Remember when we created the wildcard CNAME record for our app domain to use? This technically means that anyrandomurl.onfpwebapps.net will be pointing to the same IP address as my SharePoint site. So let’s talk about IIS bindings and how they relate to this situation:
IIS bindings
Every IIS site must have a unique binding. That means that some combination of the IP address, port and host name has to be unique on the server. This is to prevent any conflicts of multiple sites trying to serve the same requests.
Before IIS 8, in order to have multiple SSL’s, the most common thing to do was to use adifferent IP address for each SSL site. This is due to the fact that you couldn’t specify host names in the bindings for an SSL site. This leads back to the situation I’m in with my app domain configuration. My app domain is pointing to my site’s FQDN in DNS which means that it’s using the same IP address. So how will we work that out?
Step 1: Acquire a wildcard SSL for your app domain. 
(In this scenario, it is assumed you’re already using SSL for your SharePoint site itself.)
Since I’m doing this in a lab environment, I am just using a self-signed certificate. In a production environment, you will definitely want to purchase the wildcard certificate from a 3rd party certificate authority.
purchase the wildcard certificate
Step 2: Create a placeholder web application for your app domain
This step isn’t technically necessary since you can add the additional app domain binding to one of your other SharePoint sites in IIS, but I like to do it to separate my SSL bindings to different sites in IIS. This web application will have no site collections since it’s not actually hosting any app content (remember that SharePoint apps can be hosted off the SharePoint server itself). It’s basically just going to serve as a placeholder:
no site collections in the app domain
(Screenshot showing that there are no site collections in the app domain placeholder web application)
alternate access mappings
(Screenshot showing the alternate access mappings for this web application)
Step 3: Update IIS bindings to use the SSL’s
This is where the magic is going to happen. The reason we can use multiple SSL certificates with the same IP address in IIS 8 is because of the new Server Name Indication option(SNI for short). This allows us to specify host names for SSL secured sites. Here are the bindings for my two SharePoint web applications:
My app domain’s placeholder web application has one HTTPS binding that is using the wildcard certificate and no Server Name Indication (since SNI requires that you specify one host name and each app would be using a different host name).
app domain’s placeholder web application
My SharePoint site’s web application’s bindings also have one HTTPS binding that uses the site’s specific SSL certificate. This binding is using the SNI option to specify the host name:
SharePoint site’s web application’s bindings
I added a simple app part to the home page of my SharePoint site and confirmed that I am no longer receiving any SSL certificate warnings for my site or the embedded app.
Adding app to SharePoint site homepage

Hope that helped! Thanks for reading!HOW TO CONFIGURE DNS AND SSL FOR SHAREPOINT 2013 APPSOW TO CONFIGURE DNS AND SSL FOR SHAREPOINT 2013 APPS

Sunday, 11 October 2015

Add List Item in SharePoint List Using JavaScript


Step 1
Create a Web Part using Visual Studio 2013.

Create a Web Part using Visual Studio

Step 2
Open the ascx (MyFirstWebPartUserControl.ascx) and design your UI. Here I have created Employee details information.

Employee details information

The following  is the design part of the code:
  1. <div>  
  2.     <table cellpadding="10">  
  3.         <tr>  
  4.             <td colspan="2" align="center">  
  5.                 <label style="width: 200px; height: 50px; font-size: large; font: bold;">Employee Details</label>  
  6.             </td>  
  7.         </tr>  
  8.         <tr>  
  9.             <td>  
  10.                 <label style="width: 100px; height: 50px; font-size: large; font: bold;">Employee ID</label>  
  11.             </td>  
  12.             <td>  
  13.                 <input type="text" id="txtEmployeeId" style="width: 100px;" />  
  14.             </td>  
  15.         </tr>  
  16.         <tr>  
  17.             <td>  
  18.                 <label style="width: 100px; height: 50px; font-size: large; font: bold;">First Name</label></td>  
  19.             <td>  
  20.                 <input type="text" id="txtFirstName" style="width: 100px;" /></td>  
  21.         </tr>  
  22.         <tr>  
  23.             <td>  
  24.                 <label style="width: 100px; height: 50px; font-size: large; font: bold;">Last Name</label></td>  
  25.             <td>  
  26.                 <input type="text" id="txtLastName" style="width: 100px;" /></td>  
  27.         </tr>  
  28.         <tr>  
  29.             <td>  
  30.                 <label style="width: 100px; height: 50px; font-size: large; font: bold;">State</label></td>  
  31.             <td>  
  32.                 <input type="text" id="txtState" style="width: 100px;" /></td>  
  33.         </tr>  
  34.         <tr>  
  35.             <td>  
  36.                 <label style="width: 100px; height: 50px; font-size: large; font: bold;">City</label></td>  
  37.             <td>  
  38.                 <input type="text" id="txtCity" style="width: 100px;" /></td>  
  39.         </tr>  
  40.         <tr>  
  41.             <td>  
  42.                 <input type="button" id="btnSave" value="Save" onclick="createListItem();" />  
  43.   
  44.             </td>  
  45.             <td>  
  46.                 <input type="button" id="btnCancel" value="Cancel" onclick="ClearFields();" />  
  47.             </td>  
  48.         </tr>  
  49.     </table>  
  50.   
  51. </div> 
The following  is the JavaScript Code:
  1. <script type="text/javascript">  
  2.     var siteUrl = 'http://ils-jacobr:35526';  
  3.   
  4.     function createListItem() {  
  5.         var empId = document.getElementById('txtEmployeeId').value;  
  6.         var firstName = document.getElementById('txtFirstName').value;  
  7.         var lastName = document.getElementById('txtLastName').value;  
  8.         var state = document.getElementById('txtState').value;  
  9.         var city = document.getElementById('txtCity').value;  
  10.         var clientContext = new SP.ClientContext(siteUrl);  
  11.         var oList = clientContext.get_web().get_lists().getByTitle('EmployeeDetails');  
  12.         var itemCreateInfo = new SP.ListItemCreationInformation();  
  13.         this.oListItem = oList.addItem(itemCreateInfo);  
  14.         oListItem.set_item('EmployeeID', empId);  
  15.         oListItem.set_item('FirstName', firstName);  
  16.         oListItem.set_item('LastName', lastName);  
  17.         oListItem.set_item('City', city);  
  18.         oListItem.set_item('State', state);  
  19.         oListItem.update();  
  20.         clientContext.load(oListItem);  
  21.         clientContext.executeQueryAsync(Function.createDelegate(thisthis.onQuerySucceeded), Function.createDelegate(thisthis.onQueryFailed));  
  22.     }  
  23.   
  24.     function onQuerySucceeded() {  
  25.   
  26.         alert('Item created Successfully !!!!');  
  27.         document.getElementById('txtCity').value = "";  
  28.         document.getElementById('txtEmployeeId').value = "";  
  29.         document.getElementById('txtFirstName').value = "";  
  30.         document.getElementById('txtLastName').value = "";  
  31.         document.getElementById('txtState').value = "";          
  32.     }  
  33.   
  34.     function onQueryFailed(sender, args) {  
  35.   
  36.         alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());  
  37.     }  
  38.     function ClearFields() {  
  39.         document.getElementById('txtCity').value = "";  
  40.         document.getElementById('txtEmployeeId').value = "";  
  41.         document.getElementById('txtFirstName').value = "";  
  42.         document.getElementById('txtLastName').value = "";  
  43.         document.getElementById('txtState').value = "";  
  44.     }  
  45. </script> 
Step 3
Build and deploy your the solution.

Deploy

Step 4
Go to your SharePoint site and create one page under site pages. Add your web part to that page.

Add your web part in that page

Step 5
Enter the Employee details and click the Save button.

Employee details

click save button

Step 6
Go to your List and the item will display.

display

Add a Custom Search Link to Your Search Results Page in SharePoint 2013 


Search Verticals
In SharePoint 2013, there are four default search verticals displayed in the Enterprise Search Center as shown below. They are placed in the Search Navigation Web Part.

Search Navigation Web Part

When the user clicks on each vertical they are redirected to one of the following search pages:
All these results pages are available in the pages library. The Search Results Web Part are configured to use different result sources in these pages.

Search Results Web Part

The following describes how to create a search results page:
  1. Navigate to the Enterprise Search Site:https://c986.sharepoint.com/sites/Test/Enterprise%20Search/.
  2. Click on Site Actions and then click on Site Contents.

    Site Contents
  3. Click on the Pages app.

    Pages app
  4. Click on the Files tab in the ribbon interface, select Page from the New Document drop down.

    New Document
  5. Enter the Title, Description and URL for the page. Click on the Create button.

    Click on Create
  6. The Search Page (custom.aspx) is created successfully.

    Search Page custom
The following is how to create a search vertical:
  1. Click on Site Actions and then click on Site Settings.
  2. Click on Search Settings available in the Search section.

    Search Settings
  3. On the Configure Search Navigation section, click on the Add link.

    Configure Search Navigation
  4. Enter the Title and the URL (the URL of the results page we have created in the previous section).
  5. Click on the OK button.

    Click on Ok button
  6. Click on the OK button on the search settings page.
Testing
  1. Navigate to the Search default page:https://c986.sharepoint.com/sites/Test/Enterprise%20Search/Pages/default.aspx.
  2. Search for some keyword and it will be redirected to results.aspx page. You will see a new search vertical that we created.

    redirected to results
  3. Click on Custom, it will be redirected to the custom.aspx page.

    Note: You can edit the search results web part and configure your custom query on the custom.aspx page.

    Custom