Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SharePoint提供商托管的应用程序许可证检查_Sharepoint_Csom_Sharepoint Apps_Sharepoint Addin - Fatal编程技术网

SharePoint提供商托管的应用程序许可证检查

SharePoint提供商托管的应用程序许可证检查,sharepoint,csom,sharepoint-apps,sharepoint-addin,Sharepoint,Csom,Sharepoint Apps,Sharepoint Addin,我有一个SP应用程序,我希望能发布到商店 我最不想在它中实现的是许可证检查,这是我在服务器端(C#)执行的 我发现要执行此操作,首先需要从SharePoint检索当前许可证,我正试图使用以下代码执行此操作: ClientResult<AppLicenseCollection> licenseCollection = Utility.GetAppLicenseInformation(clientContext, productId); c

我有一个SP应用程序,我希望能发布到商店

我最不想在它中实现的是许可证检查,这是我在服务器端(C#)执行的

我发现要执行此操作,首先需要从SharePoint检索当前许可证,我正试图使用以下代码执行此操作:

            ClientResult<AppLicenseCollection> licenseCollection = Utility.GetAppLicenseInformation(clientContext, productId);
            clientContext.Load(clientContext.Web);
            clientContext.ExecuteQuery();
ClientResult licenseCollection=Utility.GetAppLicenseInformation(clientContext,productId);
Load(clientContext.Web);
clientContext.ExecuteQuery();
但是,执行此代码会给我一个错误:远程服务器返回一个错误:(403)禁止

我尝试使用授予应用程序的各种权限(最多可完全控制web/site/tenant)运行此应用程序,但仍然存在相同的错误


有人知道缺少什么吗?我正在从应用程序目录中获取产品ID,上下文似乎正常,因为它会返回其他类型请求的结果。

是否需要加载clientContext.Web?我正在检查我之前使用的一个代码,它只运行clientContext.ExecuteQuery()就可以工作

试试看
{
var contextToken=TokenHelper.GetContextTokenFromRequest(Page.Request);
var hostWeb=Page.Request[“SPHostUrl”];
var appWeb=Page.Request[“SPAppWebUrl”];
使用(var)clientContext=
TokenHelper.GetClientContextWithContextToken(
hostWeb、contextToken、Request.Url.Authority)
{
ClientResult许可证=
Microsoft.SharePoint.Client.Utilities.Utility。
GetAppLicenseInformation(clientContext,_productID);
clientContext.ExecuteQuery();
如果(licenses.Value.Count==0)
抛出新的InvalidOperationException(“无许可证”);
字符串licenseString=licenses.Value[0]。RawXMLLicenseToken;
}
}
捕获(例外情况除外)
{
响应.写入(“授权失败:+ex.Message”);
}

好的,我已经让它返回了许可证集合。 在我最近的一些调整之后,上下文似乎被错误地初始化了,并且读取Web权限似乎足以加载许可证

然而,我现在看到的是,我得到的许可证集合是空的。 我的应用程序尚未在商店中,我只将其部署到我的应用程序目录中,是否需要在商店中才能返回实际的许可证? 如果是这样,那最好的办法是什么呢?我真的不想发布一个未完成的应用程序


更新:我能够使用此项目中的SpapplicenceHelper.GenerateTestToken上载测试许可证:

什么是_productID?
try
{
var contextToken = TokenHelper.GetContextTokenFromRequest(Page.Request);
var hostWeb = Page.Request["SPHostUrl"];
var appWeb = Page.Request["SPAppWebUrl"];
using (var clientContext =
TokenHelper.GetClientContextWithContextToken(
hostWeb, contextToken, Request.Url.Authority))
{
 ClientResult<AppLicenseCollection> licenses =
 Microsoft.SharePoint.Client.Utilities.Utility.
 GetAppLicenseInformation(clientContext, _productID);

 clientContext.ExecuteQuery();

 if (licenses.Value.Count == 0)
     throw new InvalidOperationException("No license");
 string licenseString = licenses.Value[0].RawXMLLicenseToken;
 }
}
catch (Exception ex)
{
 Response.Write("Licensing failed: " + ex.Message);
}