以编程方式将敏感度标签应用到文件 - 可以获取标签但不能应用它们

问题描述 投票:0回答:1

我正在尝试将 Office 敏感度标签应用到 .NET Web 应用程序中的文件。 我主要基于这个演示项目:https://github.com/Azure-Samples/MipSDK-File-Razor-Sample

我的应用程序注册具有该项目中指定的正确权限。我可以获取活动标签,但是当我尝试将标签应用于文件流时,出现以下错误:

Microsoft.InformationProtection.Exceptions.ServiceDisabledException:'禁止调用主体执行该操作,CorrelationId=616b22f2-cbf0-4636-b959-a90adc68456f,CorrelationId.Description=FileHandler,HttpRequest.Id=d8d6666c-4b94-4ee1-8b4b-d7b1645acad f , ServiceDisabledError.Extent=用户'

我无法弄清楚此错误的根本原因是什么,如果我可以在代码中更改它,或者我的应用程序注册中是否仍然缺少权限。

这是相关功能:

public MemoryStream ApplyMipLabel(Stream inputStream, string labelId)
{
    IFileEngine engine = GetEngine(_defaultEngineId);

    // Create a handler with a hardcoded file name, using the input stream.
    IFileHandler handler = engine.CreateFileHandlerAsync(inputStream, "HrData.xlsx", false).GetAwaiter().GetResult();

    LabelingOptions options = new()
    {
        AssignmentMethod = AssignmentMethod.Standard
    };

    // Set the label on the handler.
    var label = engine.GetLabelById(labelId);
    handler.SetLabel(label, options, new ProtectionSettings());

    MemoryStream outputStream = new MemoryStream();

    // Commit the change and write to the outputStream.
    handler.CommitAsync(outputStream).GetAwaiter().GetResult(); // ERROR HAPPENS HERE
    return outputStream;
}
c# asp.net-core office365 microsoft-information-protection mip-sdk
1个回答
0
投票

当我尝试应用受保护的标签时,我遇到了这个确切的错误。其他标签(即未受保护的标签)工作正常,没有任何错误。幸运的是,我找到了这篇文章:https://learn.microsoft.com/en-us/information-protection/develop/concept-api-permissions,并尝试了其中列出的应用程序权限。

上面的代码示例不显示您使用的是公共客户端还是机密客户端。我的猜测是您正在使用机密客户端工作流程,就像我一样。因此,在 Microsoft Entra Admin Center 中,您需要请求 Azure Rights Management Service 的“Content.Writer”权限,如图所示。一旦将此特定权限应用于我的应用程序,就会修复 Microsoft.InformationProtection.Exceptions.ServiceDisabledException:“禁止调用主体执行操作...”服务禁用错误。我的应用程序不需要其他权限。 Application Permissions in Microsoft Entra

© www.soinside.com 2019 - 2024. All rights reserved.