URL Rewrite incompatibility

Found in

EPiServer.CMS.Core 11.15.1

Fixed in

EPiServer.CMS.Core 11.20.3

Created

Sep 14, 2020

Updated

Jan 15, 2021

Area

CMS Core

State

Closed, Fixed and tested


Description

This bug happens for BLOB downloads when they are sent to the client asynchronously and URL rewrite is configured to inject the Application Insights JavaScript.

It looks like it is related to Response.Flush called. When commenting out this line, it starts to work.
Similarly, when adding a Response.Flush() call after the synchronous transmit-method that will also start failing. Otherwise, when it copies with stream.CopyTo(), it will read/write to the stream without a flush and that works as expected.

Steps to reproduce

  • Install URL rewrite (older version is installed by default, it needs version 2): https://www.iis.net/downloads/microsoft/url-rewrite
  • Enable rewrite-config: C:\Windows\System32\inetsrv>appcmd unlock config /section:allowedServerVariables
  • Setup IIS site for Alloy
  • Install EnvVarProvider dll: gacutil /i Microsoft.Web.Hosting.EnvVarProvider.dll
  • Setup environment variable: APPINSIGHTS_INSTRUMENTATIONKEY = d06bb9f2-1af0-428c-baed-a9626a5fbdf1
  • Setup environment variable: APPINSIGHTS_JAVASCRIPT_ENABLED = true
  • Set connection strings to use azure resources
  • Upload a .html file to media assets
  • Download the .html file from media assets

Result
File is partially downloaded or browser reacts with a network error.