Windows Azure Website and static html in Blob storage

1.1k views Asked by At

So I have a .NET MVC app published in an Azure Website which should serve static html pages stored in a blob container when clicking on a corresponding hyperlink.

My questions are:

  1. The way to access a blob in Azure is https://blobtest.blob.core.windows.net/container/htmlpage1.html, however the peculiar part is when I login into my Azure Site and the url is something like: http://azuretestwebapp.azurewebsites.net/user123 and if I click on a hyperlink to my html blob it can't help but normally take me to blob azure site (well of course). Therefore I am wondering if there is a way to have a url similar to this: http://azuretestwebapp.azurewebsites.net/user123/container/htmlpage1.html considering that the html pages are stored elsewhere in Azure.
  2. If this is not feasible using an Azure Website or by storing static html pages in Blob, what would be a better approach?

Thank you in advance for your time.

2

There are 2 answers

4
theadriangreen On

You can modify your web.config for your site to forward requests for static pages to blob storage using a redirect rule. Then the static content will be stored in and served from blob storage.

Place the following in a file named web.config (or modify your existing web.config) and put the web.config in the folder site/wwwroot on your website, next to the site content.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="static" stopProcessing="true">
          <match url="static/(.*)" />
          <action type="Rewrite" url="https://blobtest.blob.core.windows.net/static/{R:1}" />          
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>
0
Dinny On

Better late than never. Azure Blob requires the host header to be set correctly also otherwise it'll 404.

<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="static" stopProcessing="true">
                    <match url="static/(.*)" />
                    <action type="Rewrite" url="https://blobtest.blob.core.windows.net/static/{R:1}" />
                    <serverVariables>
                        <set name="HTTP_HOST" value="blobtest.blob.core.windows.net" />
                    </serverVariables>
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

Please remember to Allow Server Variable {HTTP_HOST} in URL rewrite.

https://learn.microsoft.com/en-us/iis/extensions/url-rewrite-module/setting-http-request-headers-and-iis-server-variables

You could also set this in applicationhost.config section.

 <location path="Default Web Site">
        <system.webServer>
            <rewrite>
                <allowedServerVariables>
                    <add name="HTTP_HOST" />
                </allowedServerVariables>
            </rewrite>
        </system.webServer>
    </location>