Skip to content

Debugging HTTP handlers

Taritsyn edited this page May 29, 2024 · 6 revisions

As is known, in debug mode the Styles.Render and Scripts.Render helper-methods renders a references to individual assets. As a rule, when in the project uses only static CSS and JS assets, no problems should arise. But situation changes when in the project added the assets written on intermediate languages (such as LESS and TypeScript). Such assets are not translated and this could lead to the errors in web browser. Therefore, during installation of translators-modules in the Web.config file are automatically registered the debugging HTTP handlers, that produce translation of requested assets.

When using the CustomBundleResolver class capabilities of the debugging HTTP handlers is significantly expanded: item transformations, translator and postprocessors (UseInDebugMode property of postprocessor must be equals to true) from corresponding bundle will apply to requested asset.

In addition, in the BundleTransformer.Core included two debugging HTTP handlers: CssAssetHandler and JsAssetHandler, which applying the transformations from bundle (item transformations and postprocessors) to requested CSS and JS assets. If CSS or JS asset is not included in the bundle, then CssAssetHandler or JsAssetHandler pass the request to the System.Web.StaticFileHandler. Unlike other HTTP handlers, these HTTP handlers have to be registered in the Web.config file manually. To use these debugging HTTP handlers in the IIS Integrated mode, you need add to the /configuration/system.webServer/handlers element the following code:

<add name="CssAssetHandler"
  path="*.css" verb="GET"
  type="BundleTransformer.Core.HttpHandlers.CssAssetHandler, BundleTransformer.Core"
  resourceType="File" preCondition="" />
<add name="JsAssetHandler"
  path="*.js" verb="GET"
  type="BundleTransformer.Core.HttpHandlers.JsAssetHandler, BundleTransformer.Core"
  resourceType="File" preCondition="" />

To use these debugging HTTP handlers in the IIS Classic mode (this also applies to the XSP web server for Mono), you need add to the /configuration/system.web/httpHandlers element the following code:

<add path="*.css" verb="GET"
  type="BundleTransformer.Core.HttpHandlers.CssAssetHandler, BundleTransformer.Core" />
<add path="*.js" verb="GET"
  type="BundleTransformer.Core.HttpHandlers.JsAssetHandler, BundleTransformer.Core" />