<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>It's Spann, not spam</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/bspann/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/bspann/feed.xml</link>
    <description>Technical blog to provide content that developers find useful.</description>
    <lastBuildDate>Wed, 17 Apr 2019 03:40:10 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>ASP.NET MVC based Apps for SharePoint 2013 (on-premises)</title>
      <link>https://docs.microsoft.com/archive/blogs/bspann/asp-net-mvc-based-apps-for-sharepoint-2013-on-premises</link>
      <pubDate>Sat, 19 Jan 2013 12:21:00 GMT</pubDate>
      <dc:creator><![CDATA[bspann]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/bspann/2013/01/19/asp-net-mvc-based-apps-for-sharepoint-2013-on-premises/</guid>
      <description><![CDATA[Recently I was asked the following question: "Can we use ASP.NET MVC 4 for an App for...]]></description>
      <content:encoded><![CDATA[<p><span style="font-size: small;"><span style="font-family: Segoe UI Light;">Recently I was asked the following question: "Can we use ASP.NET MVC 4 for an App for SharePoint?"&nbsp; My answer was "Yes, you can."&nbsp; This blog post will walk you through creating and deploying on-premises provider-hosted app for SharePoint.&nbsp; We will utilize the server-to-server (S2S) protocol to create a high-trust app.&nbsp; Typically apps that use the server-to-server protocol run behind a firewall. </span></span></p>
<p><span style="font-size: small;"><span style="font-family: Segoe UI Light;">Please read the following <a href="https://msdn.microsoft.com/en-us/library/fp179901.aspx" target="_blank">How to: Create high-trust apps for SharePoint 2013 using the server-to-server protocol (advanced topic)</a>. This how to will walk you through the steps of configuring your IIS and SharePoint 2013 servers for S2S High Trust.&nbsp; Once you have completed the steps listed in the article, come back here and follow the steps below.</span></span></p>
<p><span style="font-size: small;"><span style="font-family: Segoe UI Light;"><span style="color: #ff0000;">[Note]</span>: In the instructions that configures your machine for server-to-server protocol, you create a Guid to be used for the Issuer ID.&nbsp; Copy that value and keep it handy.&nbsp; You will need it in later on in the exercise.&nbsp; As a practice that I use, I copy the output from PowerShell after the command "New-SPTrustedSecurityTokenIssuer" so that I can reference it if I need to.</span></span></p>
<h1><span style="font-family: Segoe UI; font-size: 14pt;">Prerequisites </span></h1>
<ul>
<li><span style="font-size: small; font-family: Segoe UI Light;">Visual Studio 2012</span></li>
<li><span style="font-size: small; font-family: Segoe UI Light;">Microsoft Office Developer Tools for Visual Studio 2012 &ndash; Preview 2</span></li>
<li><span style="font-size: small; font-family: Segoe UI Light;">SharePoint 2013 Server</span></li>
</ul>
<h1><span style="font-family: Segoe UI; font-size: 14pt;">Create the SharePoint App </span></h1>
<p style="margin-left: 18pt;"><span style="font-family: Segoe UI Light; font-size: small;">In Visual Studio 2012, choose <strong>File</strong>, <strong>New</strong>, <strong>Project</strong>.</span></p>
<p><iframe src="https://skydrive.live.com/embed?cid=A15B14F72EFFCFB1&amp;resid=A15B14F72EFFCFB1%2128090&amp;authkey=AMr1SX5pJ-ejHiA" frameborder="0" scrolling="no" width="319" height="195"></iframe></p>
<p style="margin-left: 18pt;"><span style="font-family: Segoe UI Light; font-size: small;">In the <strong>New Project</strong> wizard, expand the <strong>Visual C#</strong> node, and then expand the <strong>Office/SharePoint</strong> node. </span></p>
<p><iframe src="https://skydrive.live.com/embed?cid=A15B14F72EFFCFB1&amp;resid=A15B14F72EFFCFB1%2128091&amp;authkey=AGp64CJLWQwWQvk" frameborder="0" scrolling="no" width="319" height="220"></iframe></p>
<p style="margin-left: 18pt;"><span style="font-family: Segoe UI Light; font-size: small;">Choose <strong>Apps</strong>, and then choose to create an <strong>App for SharePoint 2013</strong> project. </span></p>
<p style="margin-left: 18pt;"><span style="font-family: Segoe UI Light; font-size: small;">Name the project <strong>HighTrustSampleApp</strong>. </span></p>
<p style="margin-left: 18pt;"><span style="font-family: Segoe UI Light; font-size: small;">Save the project in a location you choose, and then choose <strong>OK</strong>. </span></p>
<p style="margin-left: 18pt;"><span style="font-family: Segoe UI Light; font-size: small;">Select the <strong>Provider-hosted</strong> hosting option, and then choose the <strong>Next</strong> button. </span></p>
<p><iframe src="https://skydrive.live.com/embed?cid=A15B14F72EFFCFB1&amp;resid=A15B14F72EFFCFB1%2128092&amp;authkey=AOiF-8YyB2lTCUE" frameborder="0" scrolling="no" width="320" height="233"></iframe></p>
<p style="margin-left: 18pt;"><span style="font-family: Segoe UI Light; font-size: small;">Under <strong>How do you want your app to authenticate?</strong>, choose <strong>Use a certificate</strong>. </span></p>
<p><span style="font-size: small;"><iframe src="https://skydrive.live.com/embed?cid=A15B14F72EFFCFB1&amp;resid=A15B14F72EFFCFB1%2128093&amp;authkey=ACyYPdlM-rX2DKI" frameborder="0" scrolling="no" width="320" height="235"></iframe></span></p>
<p style="margin-left: 18pt;"><span style="font-family: Segoe UI Light; font-size: small;">Click the <strong>Browse</strong> button next to the <strong>Certificate location</strong> box and navigate to the location of the self-signed certificate (.pfx file) that you created. Type the password for this certificate in the <strong>Password</strong> box. Type the issuer ID in the <strong>Issuer ID</strong> box. </span></p>
<p style="margin-left: 18pt;"><span style="font-family: Segoe UI Light; font-size: small;">In the wizard, choose <strong>Finish</strong>. Much of the configuration is done when the solution opens. Two projects are created in the Visual Studio 2012 solution, one for the app for SharePoint and the other for the ASP.NET web application. </span></p>
<p><iframe src="https://skydrive.live.com/embed?cid=A15B14F72EFFCFB1&amp;resid=A15B14F72EFFCFB1%2128094&amp;authkey=ALELXDiikqbjhF0" frameborder="0" scrolling="no" width="261" height="319"></iframe></p>
<p><span style="font-size: small;"><span style="font-family: Segoe UI Light;">ASP.NET Forms project type is the default web project that is created when building an App for SharePoint 2013 using Provider-hosted option. This is not what we want. So, we need to create an ASP.NET MVC 4 project in the solution. </span></span></p>
<p style="margin-left: 18pt;"><span style="font-family: Segoe UI Light; font-size: small;">Right click on the solution in <strong>Solution Explorer</strong>. </span></p>
<p><iframe src="https://skydrive.live.com/embed?cid=A15B14F72EFFCFB1&amp;resid=A15B14F72EFFCFB1%2128095&amp;authkey=AKKk21EzOh1JFQg" frameborder="0" scrolling="no" width="319" height="198"></iframe></p>
<p style="margin-left: 18pt;"><span style="font-family: Segoe UI Light; font-size: small;">Select <strong>New Project</strong> from the context menu. </span></p>
<p style="margin-left: 18pt;"><span style="font-family: Segoe UI Light; font-size: small;">In the <strong>Visual C#</strong> node, select the <strong>Web</strong> node. </span></p>
<p><iframe src="https://skydrive.live.com/embed?cid=A15B14F72EFFCFB1&amp;resid=A15B14F72EFFCFB1%2128096&amp;authkey=AJc8GelVqdG9Mg8" frameborder="0" scrolling="no" width="320" height="221"></iframe></p>
<p style="margin-left: 18pt;"><span style="font-family: Segoe UI Light; font-size: small;">Choose <strong>ASP.NET MVC 4 Web Application</strong> project type. </span></p>
<p style="margin-left: 18pt;"><span style="font-family: Segoe UI Light; font-size: small;">Name the project <em>SPAppMvcWeb</em>. </span></p>
<p style="margin-left: 18pt;"><span style="font-family: Segoe UI Light; font-size: small;">Save the project in a location you choose, typically in the same location as you previously saved the projects that were created in the above steps, and then choose <strong>OK</strong>. </span></p>
<p style="margin-left: 18pt;"><span style="font-family: Segoe UI Light; font-size: small;">Choose <strong>Basic</strong> in the <strong>Select a template</strong> section of the <strong>New ASP.NET MVC 4 Project</strong> dialog. </span></p>
<p><iframe src="https://skydrive.live.com/embed?cid=A15B14F72EFFCFB1&amp;resid=A15B14F72EFFCFB1%2128097&amp;authkey=AJt97scguL7OeOY" frameborder="0" scrolling="no" width="320" height="290"></iframe></p>
<p style="margin-left: 18pt;"><span style="font-family: Segoe UI Light; font-size: small;">Click the <strong>OK</strong> button. </span></p>
<p><span style="font-size: small;"><span style="font-family: Segoe UI Light;">Once the project pulls down all the NuGet packages that the template needs, you should have three projects in your solution. Now we need to tell the SharePoint App to use the ASP.NET MVC project instead of the ASP.NET Web Application project. </span></span></p>
<p><iframe src="https://skydrive.live.com/embed?cid=A15B14F72EFFCFB1&amp;resid=A15B14F72EFFCFB1%2128098&amp;authkey=AEVqurDCB6411zw" frameborder="0" scrolling="no" width="250" height="319"></iframe></p>
<p style="margin-left: 18pt;"><span style="font-family: Segoe UI Light; font-size: small;">Click the SharePoint App project in Solution Explorer. </span></p>
<p style="margin-left: 18pt;"><span style="font-family: Segoe UI Light; font-size: small;">Find the property Web Project in the Properties window. If the properties window is not open, use Ctrl+W,P to bring it up.</span></p>
<p><iframe src="https://skydrive.live.com/embed?cid=A15B14F72EFFCFB1&amp;resid=A15B14F72EFFCFB1%2128099&amp;authkey=AIGNVTawpY93O-Q" frameborder="0" scrolling="no" width="290" height="320"></iframe></p>
<p style="margin-left: 18pt;"><span style="font-family: Segoe UI Light; font-size: small;">Click on the dropdown to select the different web application projects in the solution. </span></p>
<p style="margin-left: 18pt;"><span style="font-family: Segoe UI Light; font-size: small;">Select the MVC project that you just created.</span></p>
<p><span style="font-size: small;"><span style="font-family: Segoe UI Light;">Visual Studio will now prompt you, asking if you want Microsoft to help setup and configure the new Web Application to support the App for SharePoint. Click on the OK button in the dialog. Visual Studio will add all the necessary references to your project and include the TokenHelper.cs class. Also, the web.config file is modified to include entries for the Client ID and Client Secret. We will come back to this later. For now, just know that your web.config was modified for you. </span></span></p>
<p><iframe src="https://skydrive.live.com/embed?cid=A15B14F72EFFCFB1&amp;resid=A15B14F72EFFCFB1%2128100&amp;authkey=AGljW4a0QWAo5Mg" frameborder="0" scrolling="no" width="320" height="129"></iframe> <iframe src="https://skydrive.live.com/embed?cid=A15B14F72EFFCFB1&amp;resid=A15B14F72EFFCFB1%2128101&amp;authkey=AKDiA6dDSL357og" frameborder="0" scrolling="no" width="320" height="164"></iframe> <iframe src="https://skydrive.live.com/embed?cid=A15B14F72EFFCFB1&amp;resid=A15B14F72EFFCFB1%2128102&amp;authkey=AKsiZlyv47B2-Hs" frameborder="0" scrolling="no" width="320" height="281"></iframe> <iframe src="https://skydrive.live.com/embed?cid=A15B14F72EFFCFB1&amp;resid=A15B14F72EFFCFB1%2128103&amp;authkey=AKVUANLMoAb1Dls" frameborder="0" scrolling="no" width="319" height="201"></iframe></p>
<p>&nbsp; &nbsp; &nbsp;</p>
<p><span style="font-size: small;"><span style="font-family: Segoe UI Light;">So now we need to create some MVC artifacts so that we can use our application.</span></span></p>
<p style="margin-left: 18pt;"><span style="font-family: Segoe UI Light; font-size: small;">Right click on the Controllers folder in the MVC project and add a new controller.</span></p>
<p><iframe src="https://skydrive.live.com/embed?cid=A15B14F72EFFCFB1&amp;resid=A15B14F72EFFCFB1%2128104&amp;authkey=ALLrIEZgtTqruj0" frameborder="0" scrolling="no" width="319" height="149"></iframe></p>
<p style="margin-left: 18pt;"><span style="font-family: Segoe UI Light; font-size: small;">Name the controller <em>HomeController</em> and for the <strong>Template</strong>, choose <strong>Empty MVC controller</strong>. Click the <strong>Add</strong> button.</span></p>
<p><iframe src="https://skydrive.live.com/embed?cid=A15B14F72EFFCFB1&amp;resid=A15B14F72EFFCFB1%2128105&amp;authkey=AFPTz7pIdieYa3Y" frameborder="0" scrolling="no" width="320" height="208"></iframe></p>
<p style="margin-left: 18pt;"><span style="font-family: Segoe UI Light; font-size: small;">Add the following code to the controller.</span></p>
<p>&nbsp; &nbsp; &nbsp;</p>
<p><iframe style="width: 315px; height: 134px;" src="https://skydrive.live.com/embed?cid=A15B14F72EFFCFB1&amp;resid=A15B14F72EFFCFB1%2128106&amp;authkey=AJiE6YvBXEQHrY0" frameborder="0" scrolling="no" width="320" height="152"></iframe></p>
<p>&nbsp; &nbsp; &nbsp;</p>
<p><span style="font-size: small;"><span style="font-family: Segoe UI Light;">Within the <strong>Views</strong> folder, create a new sub folder called <strong>Home</strong>. </span></span></p>
<p><iframe src="https://skydrive.live.com/embed?cid=A15B14F72EFFCFB1&amp;resid=A15B14F72EFFCFB1%2128107&amp;authkey=ABVadv2WMTOYM5Q" frameborder="0" scrolling="no" width="319" height="131"></iframe></p>
<p style="padding-left: 30px;"><span style="font-size: small;"><span style="font-family: Segoe UI Light;">Right click on the folder and choose to <strong>Add,&nbsp;View</strong>. </span></span></p>
<p><iframe src="https://skydrive.live.com/embed?cid=A15B14F72EFFCFB1&amp;resid=A15B14F72EFFCFB1%2128108&amp;authkey=AFJVd1oTangHwF8" frameborder="0" scrolling="no" width="319" height="165"></iframe></p>
<p style="padding-left: 30px;"><span style="font-size: small;"><span style="font-family: Segoe UI Light;">Give the view a name of <em>Index</em>. </span></span></p>
<p><iframe src="https://skydrive.live.com/embed?cid=A15B14F72EFFCFB1&amp;resid=A15B14F72EFFCFB1%2128109&amp;authkey=AMURU78Rg0xIWro" frameborder="0" scrolling="no" width="320" height="316"></iframe></p>
<p style="padding-left: 30px;"><span style="font-size: small;"><span style="font-family: Segoe UI Light;">If the <strong>Use a layout of master page</strong> is not selected, select the option. </span></span></p>
<p style="padding-left: 30px;"><span style="font-size: small;"><span style="font-family: Segoe UI Light;">Add the following code to the view. </span></span></p>
<p><iframe src="https://skydrive.live.com/embed?cid=A15B14F72EFFCFB1&amp;resid=A15B14F72EFFCFB1%2128110&amp;authkey=AC4UKIgBmfMOcZ8" frameborder="0" scrolling="no" width="320" height="208"></iframe></p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
<p><span style="font-size: small;"><span style="font-family: Segoe UI Light;">We need to set the start page of our application to this view. To do this you have to switch to the code view of AppManifest.xml in the SharePoint App in Solution Explorer. </span></span></p>
<p style="padding-left: 30px;"><span style="font-size: small;"><span style="font-family: Segoe UI Light;">Find the &lt;StartPage&gt; xml tag and replace the contents with ~remoteAppUrl/Home?{StandardTokens}.</span></span></p>
<p><iframe src="https://skydrive.live.com/embed?cid=A15B14F72EFFCFB1&amp;resid=A15B14F72EFFCFB1%2128111&amp;authkey=AF2HVVPNfTpPrZM" frameborder="0" scrolling="no" width="320" height="178"></iframe></p>
<p><span style="font-size: small;"><span style="font-family: Segoe UI Light;">Remember what I said earlier about the web.config modifications.&nbsp; Well it is time to talk about those.&nbsp; If you would have looked at the ASP.NET Web Forms project's web.config, you would have seen a few extra <em>&lt;appSettings&gt;</em> tags.&nbsp; The ClientId will be filled in by Visual Studio when you run the application for the first time.&nbsp; So you do not need to worry about that&nbsp;app setting.&nbsp; You will need the ClientSigningCertificatePath, ClientSigningCertificatePassword, and the IssuerId.&nbsp; Here is a screenshot of what I have on my machine.&nbsp; It will be slightly different on your machine.</span></span></p>
<p><iframe src="https://skydrive.live.com/embed?cid=A15B14F72EFFCFB1&amp;resid=A15B14F72EFFCFB1%2128113&amp;authkey=AE3NEQkRuMWMGjw" frameborder="0" scrolling="no" width="317" height="102"></iframe></p>
<p><span style="font-size: small;"><span style="font-family: Segoe UI Light;">Now we can deploy and verify our app starts as expected. To do so, just press F5. SharePoint will prompt you to trust the app.</span></span></p>
<p><iframe src="https://skydrive.live.com/embed?cid=A15B14F72EFFCFB1&amp;resid=A15B14F72EFFCFB1%2128112&amp;authkey=AClYJfNSbg_78ws" frameborder="0" scrolling="no" width="320" height="153"></iframe></p>
<p><span style="font-size: small;"><span style="font-family: Segoe UI Light;">Click the <strong>Trust it</strong> button. Congratulations!&nbsp; You have just created your first ASP.NET MVC 4.0 Web Application based SharePoint App. When everything works as expected, you can delete the ASP.NET Forms project from the solution.&nbsp; You will no longer need that project.</span></span></p>
<p><iframe src="https://skydrive.live.com/embed?cid=A15B14F72EFFCFB1&amp;resid=A15B14F72EFFCFB1%2128114&amp;authkey=AEhrGGGgcUvXmfQ" frameborder="0" scrolling="no" width="319" height="49"></iframe></p>
<p>&nbsp; &nbsp; &nbsp;</p>
<h1><span style="font-family: Segoe UI; font-size: 14pt;">Add SharePoint Look and Feel to the App </span></h1>
<p><span style="font-size: small;"><span style="font-family: Segoe UI Light;">We are now going to add the SharePoint Chrome to our MVC application. </span></span></p>
<p style="padding-left: 30px;"><span style="font-size: small;"><span style="font-family: Segoe UI Light;">Under <strong>Views</strong>, <strong>Shared</strong> &ndash; modify the <em>_layouts.cshtml</em> as follows: </span></span></p>
<p><iframe src="https://skydrive.live.com/embed?cid=A15B14F72EFFCFB1&amp;resid=A15B14F72EFFCFB1%2128115&amp;authkey=APx4lorYYl_hW9s" frameborder="0" scrolling="no" width="308" height="320"></iframe> <iframe src="https://skydrive.live.com/embed?cid=A15B14F72EFFCFB1&amp;resid=A15B14F72EFFCFB1%2128116&amp;authkey=AOo76jxKODjMulM" frameborder="0" scrolling="no" width="318" height="99"></iframe></p>
<p>&nbsp;</p>
<p><span style="font-family: Segoe UI Light; font-size: small;">When you are finished, press F5. Your app should look similar to this.</span></p>
<p><iframe src="https://skydrive.live.com/embed?cid=A15B14F72EFFCFB1&amp;resid=A15B14F72EFFCFB1%2128117&amp;authkey=AKahh0U1Rcqge-M" frameborder="0" scrolling="no" width="319" height="132"></iframe></p>]]></content:encoded>
    </item>
  </channel>
</rss>