A bit of background

I was working on a site which needed to use SVGs.

I had created a media picker to choose an SVG from a folder in the Umbraco backoffice.

The site I was working on, had the media stored in azure blob storage.

It was running Umbraco 7.13.2 so SVGs were supported but it wasn't loading my SVGs.

The strange thing was, if I deleted the web.config file from the media folder, the SVGs would load.

This was the web.config file in the media folder:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <clear />
      <add name="StaticFile" path="*" verb="*" modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule" resourceType="Either" requireAccess="Read" />
    </handlers>
  </system.webServer>
</configuration>

I reached out on the Umbraco Forum and the Community Slack channel and Jeavon from Crumpled Dog gave me the answer.

The Solution

The solution was to add this line to the web.config file:

<add name="StaticFileHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.StaticFileHandler" />

But why?

I already had this set for the media location in my main web.config file so why did I need to set it again in this one?

The reason was because in the media web.config file, it was clearing all of the handlers first and then adding the StaticFile one. Meaning that any handlers that had been set in the main web.config file would be cleared first.

So the full web.config file in the media folder should look like this:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <handlers>
            <clear />
            <add name="StaticFileHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.StaticFileHandler" />
            <add name="StaticFile" path="*" verb="*" modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule" resourceType="Either" requireAccess="Read" />
        </handlers>
    </system.webServer>
</configuration>

Thanks to Jeavon for giving me the answer and for helping me work out why it worked if I deleted the web.config file.

Paul Seal

Umbraco MVP and .NET Web Developer from Derby (UK) who specialises in building Content Management System (CMS) websites using MVC with Umbraco as a framework. Paul is passionate about web development and programming as a whole. Apart from when he's with his wife and son, if he's not writing code, he's thinking about it or listening to a podcast about it.

Proudly sponsored by

Moriyama

  • Moriyama build, support and deploy Umbraco, Azure and ASP.NET websites and applications.
AppVeyor

  • CI/CD service for Windows, Linux and macOS
  • Build, test, deploy your apps faster, on any platform.
stkrs

  • Custom stickers for startups, artists and brands.
  • Bespoke easy-apply, removable, custom brand stickers printed in the UK.
elmah.io

  • elmah.io is the easy error logging and uptime monitoring service for .NET.
  • Take back control of your errors with support for all .NET web and logging frameworks.
uSync Complete

  • uSync.Complete gives you all the uSync packages, allowing you to completely control how your Umbraco settings, content and media is stored, transferred and managed across all your Umbraco Installations.