Configuration Class |
Represents the configuration context object that is used to set up the environment settings for the application. Managing configuration you can override document style applying a custom user stylesheet, or handle any web requests from the application as well as to configure scripts policy. Details are in Environment Configuration guide.
Namespace: Aspose.Html
The Configuration type exposes the following members.
Name | Description | |
---|---|---|
![]() | Configuration | Initializes a new instance of the class. |
Name | Description | |
---|---|---|
![]() | Security | Gets or sets the sandboxing flag of the configuration. Refer to article about sandboxing. |
Name | Description | |
---|---|---|
![]() ![]() | AddServiceTService | Adds the specified service to the configuration. |
![]() | Dispose | Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. |
![]() | Equals | (Inherited from Object.) |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() | GetServiceTService | Gets the requested service. |
![]() | GetType | Gets the type of the current instance. (Inherited from Object.) |
![]() | InitializeServices | Initializes the services. |
![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
You can download the complete examples and data files from GitHub.
using System; using System.Diagnostics; using System.IO; using Aspose.Html; using Aspose.Html.Net; using Aspose.Html.Services; // This message handler prints a message about start and finish processing request public class LogMessageHandler : MessageHandler { // Override the Invoke() method public override void Invoke(INetworkOperationContext context) { Debug.WriteLine("Start processing request: " + context.Request.RequestUri); // Invoke the next message handler in the chain Next(context); Debug.WriteLine("Finish processing request: " + context.Request.RequestUri); } }
public void CreateACustomMessageHandlerTest() { // Create an instance of the Configuration class using var configuration = new Configuration(); // Add the LogMessageHandler to the chain of existing message handlers var service = configuration.GetService<INetworkService>(); var handlers = service.MessageHandlers; handlers.Insert(0, new LogMessageHandler()); // Prepare path to a source document file string documentPath = Path.Combine(DataDir, "input.htm"); // Initialize an HTML document with specified configuration using var document = new HTMLDocument(documentPath, configuration); }
using Aspose.Html; using Aspose.Html.Converters; using Aspose.Html.Net; using Aspose.Html.Saving; using Aspose.Html.Services; using System; using System.Collections.Generic; using System.IO; using System.Net; using System.Text; public void SandboxingSample() { // Prepare HTML code and save it to a file var code = "<span>Hello World!!</span> " + "<script>document.write('Have a nice day!');</script>"; File.WriteAllText(Path.Combine(OutputDir, "sandboxing.html"), code); // Create an instance of Configuration using (var configuration = new Configuration()) { // Mark 'scripts' as an untrusted resource configuration.Security |= Sandbox.Scripts; // Initialize an HTML document with specified configuration using (var document = new HTMLDocument(Path.Combine(OutputDir, "sandboxing.html"), configuration)) { // Convert HTML to PDF Converter.ConvertHTML(document, new PdfSaveOptions(), Path.Combine(OutputDir, "sandboxing_out.pdf")); } } }
*OutputDir - user output folder path.