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()
{
var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext);
Guid PublishingFeature = Guid.Parse("f6924d36-2fa8-4f0b-b16d-06b7250180fa");
string fileRelativePath = @"/sites/devsite/brand/Dev.wsp";
using (var clientContext = spContext.CreateUserClientContextForSPHost())
{
var site = clientContext.Site;
clientContext.Load(site);
clientContext.ExecuteQuery();
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.
:
, ?
