User token associated with the document.
public string UserToken {get; set;} Public Property UserToken() As StringGetSet
public:property String^ UserToken{String^ get()void set(String^ value)}
The user token associated with the document. The default value is null.
User tokens can optionally be used with a document to restrict usage. Refer to Loading Using LEADTOOLS Document Library for more information.
This example will load a document from a URL into the cache and associate it with a user token. It will then try to load the document with and without a user token and show its behavior.
using Leadtools;using Leadtools.Codecs;using Leadtools.Document.Writer;using Leadtools.Svg;using LeadtoolsExamples.Common;using Leadtools.Document;using Leadtools.Caching;using Leadtools.Annotations.Engine;using Leadtools.Ocr;using Leadtools.Barcode;using Leadtools.Document.Converter;public static void UserTokenExample(){var cache = GetCache();var documentUri = new Uri("https://demo.leadtools.com/images/pdf/leadtools.pdf");const string documentId = "document-with-token";const string userToken = "my-secret";// Load from the URI without a tokenvar loadDocumentOptions = new LoadDocumentOptions();loadDocumentOptions.Cache = cache;loadDocumentOptions.DocumentId = documentId;Console.WriteLine("Loading a document into the cache without a user token");using (var document = DocumentFactory.LoadFromUri(documentUri, loadDocumentOptions)){// Make sure it does not have a user tokenAssert.IsNull(document.UserToken);document.AutoSaveToCache = false;document.AutoDeleteFromCache = false;document.SaveToCache();}// Load from cachevar loadFromCacheOptions = new LoadFromCacheOptions();loadFromCacheOptions.Cache = cache;loadFromCacheOptions.DocumentId = documentId;loadFromCacheOptions.UserToken = null;// This should workConsole.WriteLine("Loading the document from the cache without a user token");using (var document = DocumentFactory.LoadFromCache(loadFromCacheOptions)){// Make sure it does not have a user tokenAssert.IsNotNull(document);}// Load it again and set the tokenConsole.WriteLine("Setting the document user token and saving it into the cache");using (var document = DocumentFactory.LoadFromCache(loadFromCacheOptions)){// Make sure it does not have a user tokenAssert.IsNull(document.UserToken);// Set a tokendocument.UserToken = userToken;document.SaveToCache();}// This should failConsole.WriteLine("Loading the document without a user token");using (var document = DocumentFactory.LoadFromCache(loadFromCacheOptions)){// Make sure it did not loadAssert.IsNull(document);}// This should workloadFromCacheOptions.UserToken = userToken;Console.WriteLine("Loading the document with a user token");using (var document = DocumentFactory.LoadFromCache(loadFromCacheOptions)){// Make sure it has the same user tokenAssert.IsNotNull(document);Assert.AreEqual(userToken, document.UserToken);}// This should failloadFromCacheOptions.UserToken = null;Console.WriteLine("Deleting the document without a user token");bool isDeletedFromCache = DocumentFactory.DeleteFromCache(loadFromCacheOptions);// Make sure it did not get deletedAssert.IsFalse(isDeletedFromCache);// This should workloadFromCacheOptions.UserToken = userToken;Console.WriteLine("Deleting the document with a user token");isDeletedFromCache = DocumentFactory.DeleteFromCache(loadFromCacheOptions);// Make sure it got deletedAssert.IsTrue(isDeletedFromCache);}
Imports LeadtoolsImports Leadtools.CodecsImports Leadtools.Document.WriterImports Leadtools.SvgImports Leadtools.DocumentImports Leadtools.CachingImports Leadtools.Annotations.EngineImports Leadtools.BarcodeImports Leadtools.OcrImports LeadtoolsDocumentExamples.LeadtoolsExamples.CommonImports Leadtools.Document.ConverterPublic Shared Sub UserTokenExample()Dim cache As ObjectCache = GetCache()Dim documentUri As New Uri("https://demo.leadtools.com/images/pdf/leadtools.pdf")Const documentId As String = "document-with-token"Const userToken As String = "my-secret"' Load from the URI without a tokenDim loadDocumentOptions As New LoadDocumentOptions()loadDocumentOptions.Cache = cacheloadDocumentOptions.DocumentId = documentIdConsole.WriteLine("Loading a document into the cache without a user token")Using document As LEADDocument = DocumentFactory.LoadFromUri(documentUri, loadDocumentOptions)' Make sure it does Not have a user tokenAssert.IsNull(document.UserToken)document.AutoSaveToCache = Falsedocument.AutoDeleteFromCache = Falsedocument.SaveToCache()End Using' Load from cacheDim loadFromCacheOptions As New LoadFromCacheOptions()loadFromCacheOptions.Cache = cacheloadFromCacheOptions.DocumentId = documentIdloadFromCacheOptions.UserToken = Nothing' This should workConsole.WriteLine("Loading the document from the cache without a user token")Using document As LEADDocument = DocumentFactory.LoadFromCache(loadFromCacheOptions)' Make sure it does Not have a user tokenAssert.IsNotNull(document)End Using' Load it again And set the tokenConsole.WriteLine("Setting the document user token and saving it into the cache")Using document As LEADDocument = DocumentFactory.LoadFromCache(loadFromCacheOptions)' Make sure it does Not have a user tokenAssert.IsNull(document.UserToken)' Set a tokendocument.UserToken = userTokendocument.SaveToCache()End Using' This should failConsole.WriteLine("Loading the document without a user token")Using document As LEADDocument = DocumentFactory.LoadFromCache(loadFromCacheOptions)' Make sure it did Not loadAssert.IsNull(document)End Using' This should workloadFromCacheOptions.UserToken = userTokenConsole.WriteLine("Loading the document with a user token")Using document As LEADDocument = DocumentFactory.LoadFromCache(loadFromCacheOptions)' Make sure it has the same user tokenAssert.IsNotNull(document)Assert.AreEqual(userToken, document.UserToken)End Using' This should failloadFromCacheOptions.UserToken = NothingConsole.WriteLine("Deleting the document without a user token")Dim isDeletedFromCache As Boolean = DocumentFactory.DeleteFromCache(loadFromCacheOptions)' Make sure it did Not get deletedAssert.IsFalse(isDeletedFromCache)' This should workloadFromCacheOptions.UserToken = userTokenConsole.WriteLine("Deleting the document with a user token")isDeletedFromCache = DocumentFactory.DeleteFromCache(loadFromCacheOptions)' Make sure it got deletedAssert.IsTrue(isDeletedFromCache)End Sub
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document
