根据 sharepoint 应用程序的文档,我们需要始终附加 SP 主机 web url,以便应用程序可以从主机 web 获取上下文。
Sharepoint 上下文提供程序和令牌帮助类自动检测此查询字符串值并创建上下文。
在我的 asp.net mvc sharepoint 应用程序中,我有以下代码:
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();
}
它只是从主机 Web 获取未隐藏的共享点列表。
但是,这当然不是我的应用程序中的唯一页面,我想要导航到其他页面。
在 asp.net mvc 中,我看到他们呈现这样的链接:
<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>
当您检查此生成的链接时,它不使用查询字符串 SPHostUrl 检查下面的屏幕截图,检查屏幕截图底部生成的链接,您会看到它没有查询字符串参数,这意味着我无法获取共享点上下文.
问题是:如何以正确的方式呈现链接,以便它们始终在所有页面中获得正确的查询字符串参数和值?