RightsManagementInformation.LoadPublishLicense 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
从加密权限管理数据流返回嵌入的 PublishLicense。
public:
System::Security::RightsManagement::PublishLicense ^ LoadPublishLicense();
public System.Security.RightsManagement.PublishLicense LoadPublishLicense ();
member this.LoadPublishLicense : unit -> System.Security.RightsManagement.PublishLicense
Public Function LoadPublishLicense () As PublishLicense
返回
嵌入的 PublishLicense;或者 null
(如果包中不包含 PublishLicense)。
例外
该类的当前版本无法读取此包中的权限管理信息。
示例
下面的示例显示如何使用 LoadPublishLicense 方法。
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.")