IT tutorials
 
Technology
 

UNDERSTANDING THE THREE APPS FOR SHAREPOINT DEPLOYMENT MODELS (part 2) - Autohosted

8/22/2013 9:45:44 AM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

Autohosted

The Autohosted deployment model is a significant departure from previous SharePoint applications. In this model you build Apps for SharePoint, but the code is seamlessly deployed to Windows Azure in the background — so SharePoint automatically creates the cloud-hosted app for you. Thus, for all intents and purposes code looks like it’s running on SharePoint, when in fact in the background it’s deployed to a special Office 365 Windows Azure instance (so in effect a different domain) and registered as an authenticated and authorized app with SharePoint.

You don’t have complete access to the entire platform capabilities of the Windows Azure platform with the Autohosted deployment model; however, you do have enough of the platform to build some interesting applications. In essence, you can leverage Windows Azure Web Sites and Windows Azure SQL Database in the Autohosted model. To help illustrate the Autohosted deployment model, take a look at the following example.

TRY IT OUT: Creating an Autohosted App (AutohostedEmployeeList.zip)
To create an Autohosted app, follow these steps:
1. Open Visual Studio 2012 and click File ⇒ New Project.
2. Navigate to the Office/SharePoint option, select Apps, and then click App for SharePoint 2013.
3. Provide a name for the app (AutohostedEmployeeList) and a location, and then click OK (see Figure 9).

FIGURE 9

image
4. In the New App for SharePoint wizard, add your O365 SharePoint developer site URL. Click Validate and enter your O365 credentials to cache the developer site credentials with your project.
5. Select Autohosted from the How do you want to host your app for SharePoint? drop-down list (see Figure 10).

FIGURE 10

image
6. Click Finish.
7. Double-click the Default.aspx page and click the Source tab at the bottom of the Visual Studio IDE.
8. Replace the code in the Default.aspx page with the following bolded code:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" 
Inherits="AutohostedEmployeeListWeb.Pages.Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head runat="server">
    <title>Employee List</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>Employee List</div>
        <table>
            <tr><td><asp:Label ID="lblName" runat="server" Text="Name:" 
Font-Names="Calibri"></asp:Label></td>
            <td><asp:TextBox ID="txtbxName" runat="server" Width="205px">
</asp:TextBox></td></tr>
            <tr><td><asp:LinkButton ID="lnkbtnAddEmployee" 
runat="server" Font-Names="Calibri" 
OnClick="lnkbtnAddEmployee_Click">Add Employee</asp:LinkButton></td>
            <td></td></tr>
            <tr><td></td><td><asp:ListBox ID="lstbxEmployee" 
runat="server" Width="212px" Font-Names="Calibri"></asp:ListBox></td>
            </tr>
            <tr><td><asp:Label ID="lblErrorMsg" runat="server" Text="" 
Font-Names="Calibri"></asp:Label></td></tr>
        </table>
    </form>
</body>
</html>
9. Switch to the Design view. You should see something similar to Figure 11. The user interface enables you to add a name into a text box and then add the name to the list box.

FIGURE 11

image
10. Right-click the Default.aspx page in Solution Explorer and select View Code. The C# code-behind for the ASP.NET page opens.
11. Replace the code in the Default.aspx.cs page with the following bolded code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
 
namespace AutohostedEmployeeListWeb.Pages
{
    public partial class Default : System.Web.UI.Page
    {
        string strEmployeeName = "";
        SharePointContextToken contextToken;
        string accessToken;
        Uri sharepointUrl;
 
        protected void Page_Load(object sender, EventArgs e)
        {
            TokenHelper.TrustAllCertificates();
            TokenHelper.TrustAllCertificates();
            string contextTokenString = TokenHelper.GetContextTokenFromRequest(Request);
 
            if (contextTokenString != null)
            {
                contextToken = TokenHelper.ReadAndValidateContextToken(contextTokenString, 
Request.Url.Authority);
                sharepointUrl = new Uri(Request.QueryString["SPHostUrl"]);
                accessToken = TokenHelper.GetAccessToken(contextToken,
 sharepointUrl.Authority).AccessToken;
                lnkbtnAddEmployee.CommandArgument = accessToken;
            }
 
        }
 
        protected void lnkbtnAddEmployee_Click(object sender, EventArgs e)
        {
            string accessToken = ((LinkButton)sender).CommandArgument;
 
            if (IsPostBack)
            {
                sharepointUrl = new Uri(Request.QueryString["SPHostUrl"]);
            }
 
            strEmployeeName = txtbxName.Text;
 
            if (txtbxName.Text != "")
            {
                lstbxEmployee.Items.Add(new ListItem(strEmployeeName));
            }
            else
            {
                lblErrorMsg.Text = "Please enter a valid name."; 
            }
        }
    }
}
12. Right-click the top-level SharePoint project and select Publish. This builds your project and creates the .APP package. At this point, you can follow the exact same process you did earlier in “Creating a SharePoint-Hosted App,” using steps 9–16 to upload, deploy, and explicitly trust the SharePoint app.
13. When you’re done, click the Site Contents link, and click the tile for the newly added App for SharePoint. Your Autohosted app loads.
14. Add some names into the Name field, and then click the Add Employee link to add the names to the list box. Your app should look similar to Figure 12.

FIGURE 12

image
How It Works
The Autohosted app is a lightweight cloud-hosted application that auto-deploys code into Windows Azure and then surfaces this code within SharePoint 2013. In this example, you created a simple employee list app that enables the user to enter and add some names to a list box. In the code, you used a set of class-level objects to store key variables such as the name of the employee (strEmployeeName), security token data (contextToken and accessToken), and SharePoint URI (sharepointUri). The key event method (lnkbtnAddEmployee_Click) was triggered by the link button.
A couple things worth noting: With the new hosted models, the question of how you authenticate your app is an important one. SharePoint 2013 introduces a new authorization model that leverages OAuth to register apps and events within that app with SharePoint. At a high level, a SharePoint App requests permissions when it is installed — you explicitly trust the app that you’re installing into your SharePoint instance. If you do not trust the app, it will not be installed. To facilitate trusting the app, you set the security token using the TokenHelper class, but then you needed to ensure that token was tied to the object sending the request (LinkButton object). Also, within the lnkbtnAddEmployee_Click event, you’re configuring the security against the SharePoint URI as well. Setting trust and security context for the app are two critical aspects of the new world of cloud apps.
Beyond the security elements, the following code that you used in the exercise is fairly straightforward: you’re assigning the strEmployeeName string variable with the text the user enters into the Name field. Then, assuming the text field is not null, you’re adding it to the list box.
...
        protected void lnkbtnAddEmployee_Click(object sender, EventArgs e)
        
            string accessToken = ((LinkButton)sender).CommandArgument;
 
            if (IsPostBack)
            {
                sharepointUrl = new Uri(Request.QueryString["SPHostUrl"]);
            }
 
            strEmployeeName = txtbxName.Text;
 
            if (txtbxName.Text != "")
            {
                lstbxEmployee.Items.Add(new ListItem(strEmployeeName));
            }
            else
            {
                lblErrorMsg.Text = "Please enter a valid name."; 
            }
}
...
You might have noticed the new URL for your Autohosted app; it probably looks something like the following:
https://a9d21e97-5c8d-4f75-9804-b548b8df8d21.o365apps.net/Pages/Default.aspx?SPHostUrl=https%3a%2f%myspsite.sharepoint.com%2fsites%2fspdev&SPLanguage=en-US
From this URL, you can begin to see how the new cloud-hosted app model leverages a GUID specific to your app, deploys it to Windows Azure (using the O365apps.net domain), and then appends a set of standard tokens to ensure the application integrates and maps to your SharePoint site. This is built from the following element within the AppManifest.xml file.
 <StartPage>~remoteAppUrl/Pages/Default.aspx?{StandardTokens}</StartPage>
Of course, many other configuration options are available to you within the AppManifest.xml file, and you can build many interesting apps using the Autohosted deployment model.

The Autohosted model is one of two cloud-hosted app models that are new to SharePoint 2013. Autohosted provides the automated deployment and management of your cloud-hosted app, but it does come with some restrictions. For example, you have limited surface area for leveraging Windows Azure, database size limits of the SQL Database, and no direct connection string access to the SQL Database. The other cloud-hosted model, the Provider-hosted app, gives you much more flexibility and allows you to draw on all of the Windows Azure features.

 
Others
 
- UNDERSTANDING THE THREE APPS FOR SHAREPOINT DEPLOYMENT MODELS (part 1) - SharePoint-Hosted
- SHAREPOINT 2013 APP MODEL : Apps for Office, Apps for SharePoint
- Microsoft Dynamic AX 2009 : The Database Layer - Unicode Support
- Microsoft Dynamic AX 2009 : The Database Layer - Company Accounts
- Microsoft Dynamic AX 2009 : The Database Layer - Record Identifiers
- SQL Server 2008 R2 : Filtered Indexes and Statistics - Creating and Using Filtered Indexes
- SQL Server 2008 R2 : Index Design Guidelines - Indexed Views, Indexes on Computed Columns
- SQL Server 2008 R2 : Index Design Guidelines
- Windows Server 2008 : Manipulating Users and Groups with the net Command, Modifying NTFS Permissions with icacls
- Windows Server 2008 : Manipulating Shares with net share, Mapping Drives with net use
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us