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.

Inheritance Hierarchy
SystemObject
  Aspose.HtmlConfiguration

Namespace: Aspose.Html
Assembly: Aspose.HTML (in Aspose.HTML.dll) Version: 22.4
Syntax
public class Configuration : IServiceProvider, 
	IServiceContainer, IDisposable

The Configuration type exposes the following members.

Constructors
  NameDescription
Public methodConfiguration

Initializes a new instance of the class.

Properties
  NameDescription
Public propertySecurity

Gets or sets the sandboxing flag of the configuration. Refer to article about sandboxing.

Methods
  NameDescription
Public methodCode exampleAddServiceTService
Adds the specified service to the configuration.
Public methodDispose
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as a hash function for a particular type.
(Inherited from Object.)
Public methodGetServiceTService
Gets the requested service.
Public methodGetType
Gets the type of the current instance.
(Inherited from Object.)
Protected methodInitializeServices
Initializes the services.
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Remarks

You can download the complete examples and data files from GitHub.

Examples
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);
}
Examples
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.

See Also