3. Understanding app code isolation
When you develop a SharePoint app,
you obviously need to write custom code to implement your business
logic, and that code must run some place other than on the web servers
in the hosting SharePoint farm. The SharePoint app model provides you
with two places to run your custom code. First, a SharePoint app can
contain client-side
code that runs inside the browser on the user’s computer. Second, a
SharePoint app can contain server-side code that runs in an external
website that is implemented and deployed as part of the app itself.
There are many different ways in which you can design and implement
a SharePoint app. For example, you could create a SharePoint app that
contains only client-side resources such as web pages and client-side
JavaScript code that are served up by the SharePoint host environment.
This type of app is known as a SharePoint-hosted app because it is contained entirely within the app web. You could write a SharePoint-hosted app that uses Microsoft Silverlight, Microsoft VBScript, Flash, or whatever client-side technology you prefer.
Now, imagine that you want to create a second SharePoint app in
which you want to write server-side code in a language such as C#. This
type of SharePoint app will require its own external website so that
your server-side code has a place to execute outside of the SharePoint
host environment. In SharePoint 2013 terminology, a SharePoint app with
its own external website is known as a cloud-hosted app, and the external website is known as the remote web. The diagram in Figure 2 shows the key architectural difference between a SharePoint-hosted app and a cloud-hosted app.
From the diagram in Figure 2, you can see that both SharePoint-hosted apps and cloud-hosted
apps have a start page that represents the app’s primary entry point.
With a SharePoint-hosted app, the app’s start page is served up by the
SharePoint host; however, with a cloud-hosted app, the start page is
served up from the remote web. Therefore, the SharePoint host
environment must track the remote web URL for each cloud-hosted app
that has been installed so that it can redirect users to the app’s
start page.
There is infrastructure in the SharePoint host environment that creates a client-side JavaScript component known as an app launcher that is used to redirect the user from a page served up by the SharePoint host environment over to the remote web.
When you decide to develop a cloud-hosted SharePoint app, you must
often take on the responsibility of hosting the app’s remote web.
However, this responsibility of creating and deploying a remote web
along with a SharePoint app also comes with a degree of flexibility.
You can implement the remote web associated with a SharePoint app by
using any existing web-based development platform.
For example, the remote web for a cloud-hosted SharePoint app could
be implemented by using a non-Microsoft platform such as Java, LAMP, or
PHP. However, the easiest and the most common approach for SharePoint
developers is to design and implement the remote web for cloud-hosted
apps by using ASP.NET web forms or MVC4.