Azure CDN Blob Storage Case Sensitive Issue

misc_vol4_019

If you’ve done any work with Azure Blob storage, you already know that Blob storage is case sensitive.  If you’ve hooked the Azure CDN to blob storage, it is also case sensitive.

You are probably reading this article because you’ve already run into this problem.

We ran into this problem when we were moving a site from an existing CDN to Azure.  The current site was on domain A and the resources hosted by the CDN were on domain B.  But the URLs to those resources were in various cases.  To make matters worse, there were multiple sites.  So it wasn’t a simple matter of just fixing up the case of one site.

So we were looking for some way to make the CDN case insensitive, which you can’t do, when I finally thought, “Why don’t we make it so that it doesn’t matter with a response filter?”  I’ve done this before when I needed to make global changes and it worked well.

Then I remembered, the URL Rewriting module for IIS7 does this for us.  And since this module is installed by default on Azure, all we needed to do was:

  • Make everything in blob storage lowercase
  • Install the redirect rules in web.config

Here is the web.config rules:

<rewrite>
  <outboundRules>
    <rule name="CSCAssets" preCondition="IsHtml"
        stopProcessing="true">
      <match filterByTags="Img"
         pattern="http://(www\.)?domain\.com/(.*)" />
      <action type="Rewrite"
         value="http://domain.com/{ToLower:{R:2}}" />
            <conditions logicalGrouping="MatchAny" />
    </rule>
    <preConditions>
      <preCondition name="IsHtml">
         <add input="{RESPONSE_CONTENT_TYPE}"
            pattern="^text/html" />
      </preCondition>
        </preConditions>
      </outboundRules>
    </rewrite>

This will force any URL pointing to http://www.domain.com or http://domain.com to point to http://domain.com and force it all to lowercase on the way back to the client’s browser.

Related Post

2 Responses to “Azure CDN Blob Storage Case Sensitive Issue”

Leave a Reply

Comment Policy:

  • You must verify your comment by responding to the automated email that is sent to your email address. Unverified comments will never show.Leave a good comment that adds to the conversation and I'll leave your link in.
  • Leave me pure spam and I'll delete it.
  • Leave a general comment and I'll remove the link but keep the comment.

Notify me of followup comments via e-mail

Bear