How to add required share settings for APPS in asp.net mvc applications?

According to the documentation for sharepoint applications, we always need to add the SP website URL so that the application can get context from the web host.

The context context provider and the token help class automatically determine this request value and create a context.

In my sharepoint mvc asp.net application, I have this code:

 public ActionResult InstallDesignPackage()
{
    // Use TokenHelper to get the client context and Title property.
    // To access other properties, the app may need to request permissions
    // on the host web.
    var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext);
    // Publishing feature GUID to use the infrastructure for publishing
    Guid PublishingFeature = Guid.Parse("f6924d36-2fa8-4f0b-b16d-06b7250180fa");
    // The site-relative URL of the design package to install.
    // This sandbox design package should be uploaded to a document library
    // for practical purpose this can be a configuration setting in web.config.
    string fileRelativePath = @"/sites/devsite/brand/Dev.wsp";
    //string fileUrl = @"https://xxx.sharepoint.com/_catalogs/solutions/LV%20Team%20Site%20Design%20Package-1.0.wsp";
    using (var clientContext = spContext.CreateUserClientContextForSPHost())
    {
        // Load the site context explicitly or while installing the API, the path for
        // the package will not be resolved.
        // If the package cannot be found, an exception is thrown.
        var site = clientContext.Site;
        clientContext.Load(site);
        clientContext.ExecuteQuery();
        // Validate whether the Publishing feature is active.
        if (Helpers.FeatureHelper.IsSiteFeatureActivated(clientContext, PublishingFeature))
        {
            DesignPackageInfo info = new DesignPackageInfo()
            {
                PackageGuid = Guid.Empty,
                MajorVersion = 1,
                MinorVersion = 1,
                PackageName = "Dev"
            };
            Console.WriteLine("Installing design package ");
            DesignPackage.Install(clientContext, clientContext.Site, info, fileRelativePath);
            clientContext.ExecuteQuery();
            Console.WriteLine("Applying design package");
            DesignPackage.Apply(clientContext, clientContext.Site, info);
            clientContext.ExecuteQuery();
        }
    }
    return View();
}

It simply retrieves a list of hidden shared lists from the host network.

However, of course, this is not the only page in my application, I want to have navigation to other pages.

In asp.net mvc, I saw how they display such links:

<div class="navbar">
    <div class="container">
        <ul class="nav navbar-nav">
            <li>@Html.ActionLink("About", "About", "Home")</li>
            <li>@Html.ActionLink("Contact", "Contact", "Home")</li>
<li>@Html.ActionLink("Install Design Package", "InstallDesignPackage", "Home")</li>

        </ul>
    </div>
</div>

, , querystring SPHostUrl , , , , , sharepoint.

: , ?

enter image description here

+4
1

, , .

.

 [SharePointContextFilter]

. .

<li>@Html.ActionLink("Install Design Package", "InstallDesignPackage", "Home", new { SPHostUrl = SharePointContext.GetSPHostUrl(HttpContext.Current.Request).AbsoluteUri },null)</li>

, : http://levalencia-public.sharepoint.com/Pages/2014/03/Sharepoint-App---ASP-NET-MVC-Navigation-Link-with-correct-querystring-parameters.aspx

+6

Source: https://habr.com/ru/post/1530783/


All Articles