Skip to content

ASP.NET Extensions

Andrey Taritsyn edited this page Aug 20, 2015 · 15 revisions

Prior to WebMarkupMin version 2.0, configuring of ASP.NET extensions were made by using the Web.config file. Now during configuration instead of the declarative approach (using the configuration file) is used in the imperative approach (using the program code).

The rejection of the declarative approach was due to the following reasons:

  1. Microsoft for several years, uses an imperative approach for configuration of individual parts of ASP.NET (for example, Web API or Web Optimization Framework).
  2. ASP.NET 5 no longer supports the Web.config files.

Extensions for ASP.NET 4.X and ASP.NET 5 use different configuration models. In ASP.NET 4.X configuring of extensions are made through special classes: WebMarkupMinConfiguration, HtmlMinificationManager, XhtmlMinificationManager and XmlMinificationManager. In ASP.NET 5 configuration of extension is based on the Options framework and using the following classes: WebMarkupMinOptions, HtmlMinificationOptions, XhtmlMinificationOptions and XmlMinificationOptions. However, these configuration models have a lot in common.

WebMarkupMin сommon configuration

WebMarkupMinConfiguration and WebMarkupMinOptions classes inherit WebMarkupMinConfigurationBase class, which has the following properties:

Property name Data type Default value Description
DisableMinification Boolean false Flag for whether to disable markup minification.
DisableCompression Boolean false Flag for whether to disable HTTP compression of content.
MaxResponseSize Int32 -1 Maximum size of the response (in bytes), in excess of which disables the minification of markup. If this property is set equal to -1, then checking of the response size is not performed.
DisablePoweredByHttpHeaders Boolean false Flag for whether to disable the *-Minification-Powered-By HTTP headers (e.g. X-HTML-Minification-Powered-By: WebMarkupMin)

Markup minification managers and options

All classes of markup minification managers and options have IncludedPages and ExcludedPages properties, that allow to include/exclude site pages from processing by corresponding markup minifier. These properties are of type IList<IUrlMatcher>, and by default contains the empty lists, i.e. by default filtering is disabled.

There are 3 built-in implementations of IUrlMatcher interface:

  1. ExactUrlMatcher. As a pattern used the URL (e.g., new ExactUrlMatcher("/contact")).
  2. RegexUrlMatcher. As a pattern used a ECMAScript standard compliant regular expression (e.g., new RegexUrlMatcher(@"^/minifiers/x(?:ht)?ml-minifier$")).
  3. WildcardUrlMatcher. Used a pattern, that supports Wildcard syntax (e.g., new WildcardUrlMatcher("/minifiers/x*ml-minifier")). This syntax supports 2 special characters: * (match any number of any characters) and ? (match exactly one character).

By default all of the above implementations of IUrlMatcher interface during matching is not case-sensitive. To change this behavior you need to pass to constructor of class as the second parameter value equals to true (e.g., new ExactUrlMatcher("/Contact", true)).