Home > CMS- Content Management System > Sharepoint > What is the Host Web URL and App Web URL in SharePoint add-in?

What is the Host Web URL and App Web URL in SharePoint add-in?

This post was most recently updated on October 4th, 2017

In the first post of this series I introduced how to create a basic HelloWorld SharePoint Hosted Add-in.

In this article we will discuss another important topic Host Web URL and App Web URL.

Before start let understand What is the Host Web and App Web.

Host Web: SharePoint site where our app will install. It always be a specific domain name. It is Main Site of subweb (App Web). 

Host Web URL

App Web : SharePoint site where our app will deploy. App web is an isolated domain but it still inside in the Host Web. App Web domain contains main domain as well as App Hash URL ( Random Unique ID ). After Every deployment it will change.

App Web URL

App Hash : It is a Hexa-Decimal Random number generated internally when an add-in is deploy or install. The App Hash is part of App Web URL. The App Hash instance supports multiple group of users or tenant environments, for each tenant it provide unique domain name for the add-in. We can use same App Hash prefix URL if we are not in tenant environments.

App Name: App Name is set by developer.

 

Getting the URLs for the Host Web and App Web within an SharePoint add-in.

To get the Host Web URL and App Web URL we need to parse the current URL using JavaScript. If we carefully check the deploy app URL,It contains SPHostUrl and SPAppWebUrl query string parameter which contains Host Web and App Web URL. On each app deployment app web add Dynamic hexadecimal unique value in domain prefix so every time we need to parse the current URL.

So Below function getQueryStringParameter(param) will return the value of given parameter.

Call getQueryStringParameter(param) function in document.ready or document.load.

Instead of above method we can also use _spPageContextInfo object to retrieve Host Web and App Web URL. it simply great work in both situations.

So the question is, Why do SharePoint create separate domain for an add-in?

There are Two reason.

  1. SharePoint Add-in may have its own permissions and it’s not necessary the user who is installing the app has same permission as Add-ins, so with separate domain SharePoint identify the add-in requests and verify the permissions of the add-in. For more information about add-in permissions, please see the Add-in permissions article.
  2. The same-origin policy is an important concept in the any web application security model. SharePoint takes advantage of the browser’s same origin policy with it’s own domain.

Below action we can perform with the App Web URL

  • Fetching Item from App List/Library
  • Fetching Item from Host site List/Library
  • Add/Edit/Update of list item.
  • Get the App Web part properties 

Further reading of this series:

How to create Hello World SharePoint Hosted Add-in

About add-in permissions in SharePoint Hosted Add-Ins

Hope you find it helpful. If you liked this article, then please share and comment.

This Article is TAGGED in , , . BOOKMARK THE permalink.

Avatar photo
Chintan Upadhayay
I am a senior web developer with more than 4+ years experience in WordPress, PHP, MySQL, HTML, CSS, jQuery and other web technologies. I am the beginner in SharePoint and Learning SharePoint.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">