gpt4 book ai didi

c# - 如何在 asp.net mvc 应用程序中附加 APPS 所需的共享点参数?

转载 作者:太空狗 更新时间:2023-10-29 22:59:12 26 4
gpt4 key购买 nike

根据 Sharepoint 应用程序的文档,我们需要始终附加 SP 主机 Web URL,以便应用程序可以从主机 Web 获取上下文。

Sharepoint 上下文提供程序和 token 帮助类自动检测此查询字符串值并创建上下文。

在我的 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检查下面的屏幕截图,检查屏幕截图底部生成的链接,您会看到它没有查询字符串参数,这意味着我无法获得共享点上下文。

问题是:我怎样才能以正确的方式呈现链接,以便它们始终在所有页面中获得正确的查询字符串参数和值??

enter image description here

最佳答案

几天后,这很简单,但真的很难找到与我遇到的问题相同的资源。

第一。 Controller Action 需要用这个属性包围

 [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

关于c# - 如何在 asp.net mvc 应用程序中附加 APPS 所需的共享点参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22276106/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com