RightsManagementInformation.LoadUseLicense(ContentUser) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
从加密权限管理数据流返回指定用户的嵌入 UseLicense。
public:
System::Security::RightsManagement::UseLicense ^ LoadUseLicense(System::Security::RightsManagement::ContentUser ^ userKey);
public System.Security.RightsManagement.UseLicense LoadUseLicense (System.Security.RightsManagement.ContentUser userKey);
member this.LoadUseLicense : System.Security.RightsManagement.ContentUser -> System.Security.RightsManagement.UseLicense
Public Function LoadUseLicense (userKey As ContentUser) As UseLicense
参数
- userKey
- ContentUser
要为其返回 UseLicense 的用户或用户组。
返回
指定用户的 UseLicense;或 null
(如果包中不包含与给定的 userKey
相匹配的 UseLicense)。
例外
userKey
参数为 null
。
该类的当前版本无法读取此包中的权限管理信息。
示例
下面的示例显示如何使用 LoadUseLicense 方法。
ShowStatus(" Opening the encrypted Package.");
EncryptedPackageEnvelope ePackage =
EncryptedPackageEnvelope.Open(xpsFile, FileAccess.ReadWrite);
RightsManagementInformation rmi =
ePackage.RightsManagementInformation;
ShowStatus(" Looking for an embedded UseLicense for user:\n " +
currentUserId + " [" + _authentication + "]");
UseLicense useLicense =
rmi.LoadUseLicense(
new ContentUser(currentUserId, _authentication));
ReadOnlyCollection<ContentGrant> grants;
if (useLicense == null)
{
ShowStatus(" No Embedded UseLicense found.\n " +
"Attempting to acqure UseLicnese\n " +
"from the PublishLicense.");
PublishLicense pubLicense = rmi.LoadPublishLicense();
ShowStatus(" Referral information:");
if (pubLicense.ReferralInfoName == null)
ShowStatus(" Name: (null)");
else
ShowStatus(" Name: " + pubLicense.ReferralInfoName);
if (pubLicense.ReferralInfoUri == null)
ShowStatus(" Uri: (null)");
else
ShowStatus(" Uri: " +
pubLicense.ReferralInfoUri.ToString());
useLicense = pubLicense.AcquireUseLicense(_secureEnv);
if (useLicense == null)
{
ShowStatus(" User DOES NOT HAVE RIGHTS\n " +
"to access this document!");
return false;
}
}// end:if (useLicense == null)
ShowStatus(" UseLicense acquired.");
ShowStatus(" Opening the encrypted Package.")
Dim ePackage As EncryptedPackageEnvelope = EncryptedPackageEnvelope.Open(xpsFile, FileAccess.ReadWrite)
Dim rmi As RightsManagementInformation = ePackage.RightsManagementInformation
ShowStatus(" Looking for an embedded UseLicense for user:" & vbLf & " " & currentUserId & " [" & _authentication & "]")
Dim useLicense As UseLicense = rmi.LoadUseLicense(New ContentUser(currentUserId, _authentication))
Dim grants As ReadOnlyCollection(Of ContentGrant)
If useLicense Is Nothing Then
ShowStatus(" No Embedded UseLicense found." & vbLf & " " & "Attempting to acqure UseLicnese" & vbLf & " " & "from the PublishLicense.")
Dim pubLicense As PublishLicense = rmi.LoadPublishLicense()
ShowStatus(" Referral information:")
If pubLicense.ReferralInfoName Is Nothing Then
ShowStatus(" Name: (null)")
Else
ShowStatus(" Name: " & pubLicense.ReferralInfoName)
End If
If pubLicense.ReferralInfoUri Is Nothing Then
ShowStatus(" Uri: (null)")
Else
ShowStatus(" Uri: " & pubLicense.ReferralInfoUri.ToString())
End If
useLicense = pubLicense.AcquireUseLicense(_secureEnv)
If useLicense Is Nothing Then
ShowStatus(" User DOES NOT HAVE RIGHTS" & vbLf & " " & "to access this document!")
Return False
End If
End If ' end:if (useLicense == null)
ShowStatus(" UseLicense acquired.")