Loading of external resources containing by a document
Loading of external resources containing by a document
Leave feedback
If the document contains external resources, such as images, GroupDocs.Viewer loads them when rendering a document. This allows the document to display correctly, but is a potential security risk.
GroupDocs.Viewer allows you to manage loading of external resources contained by a document. These features are supported for the following formats:
Use the LoadOptions object to manage loading of external resources.
Skip loading of external resources
The following code snippet shows how to deny loading of external resources:
usingGroupDocs.Viewer;usingGroupDocs.Viewer.Options;// ...LoadOptionsloadOptions=newLoadOptions();loadOptions.SkipExternalResources=true;// Skip loading of external resourcesusing(Viewerviewer=newViewer("business-flyer.docx",loadOptions)){HtmlViewOptionsviewOptions=HtmlViewOptions.ForEmbeddedResources();viewer.View(viewOptions);}
ImportsGroupDocs.ViewerImportsGroupDocs.Viewer.Options' ...
ModuleProgramSubMain(argsAsString())DimloadOptionsAsLoadOptions=NewLoadOptions()loadOptions.SkipExternalResources=True' Skip loading of external resources
UsingviewerAsViewer=NewViewer("business-flyer.docx",loadOptions)DimviewOptionsAsHtmlViewOptions=HtmlViewOptions.ForEmbeddedResources()viewer.View(viewOptions)EndUsingEndSubEndModule
The following images show the output file with and without external resources (see top right corner):
loadOptions.SkipExternalResources = false
loadOptions.SkipExternalResources = true
Manage a safelist for loading external resources
The following code snippet shows how to allow loading of external resources from specific URLs:
usingGroupDocs.Viewer;usingGroupDocs.Viewer.Options;// ...LoadOptionsloadOptions=newLoadOptions();loadOptions.SkipExternalResources=true;// Skip loading of all external resourcesloadOptions.WhitelistedResources.Add("avatars.githubusercontent.com");//Enable loading of external resources that has `avatars.githubusercontent.com` fragment in resource URL. using(Viewerviewer=newViewer("business-flyer.docx",loadOptions)){HtmlViewOptionsviewOptions=HtmlViewOptions.ForEmbeddedResources();viewer.View(viewOptions);}
ImportsGroupDocs.ViewerImportsGroupDocs.Viewer.Options' ...
ModuleProgramSubMain(argsAsString())DimloadOptionsAsLoadOptions=NewLoadOptions()loadOptions.SkipExternalResources=True' Skip loading of all external resources
loadOptions.WhitelistedResources.Add("avatars.githubusercontent.com")'Enable loading of external resources that has `avatars.githubusercontent.com` fragment in resource URL.
UsingviewerAsViewer=NewViewer("business-flyer.docx",loadOptions)DimviewOptionsAsHtmlViewOptions=HtmlViewOptions.ForEmbeddedResources()viewer.View(viewOptions)EndUsingEndSubEndModule
Set timeout for loading of external resources
The default timeout is 30 seconds. GroupDocs.Viewer allows you to change this value.
The following code snippet shows how to set a timeout to load external resources:
usingSystem;usingGroupDocs.Viewer;usingGroupDocs.Viewer.Options;// ...// Specify a timeout.LoadOptionsloadOptions=newLoadOptions();loadOptions.ResourceLoadingTimeout=TimeSpan.FromSeconds(5);// Render a file.using(Viewerviewer=newViewer("sample.docx",loadOptions)){HtmlViewOptionsviewOptions=HtmlViewOptions.ForEmbeddedResources();viewer.View(viewOptions);}
ImportsSystemImportsGroupDocs.ViewerImportsGroupDocs.Viewer.Options' ...
ModuleProgramSubMain(argsAsString())' Specify a timeout.
DimloadOptionsAsLoadOptions=NewLoadOptions()loadOptions.ResourceLoadingTimeout=TimeSpan.FromSeconds(5)' Render a file.
UsingviewerAsViewer=NewViewer("sample.docx",loadOptions)DimviewOptionsAsHtmlViewOptions=HtmlViewOptions.ForEmbeddedResources()viewer.View(viewOptions)EndUsingEndSubEndModule
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.