2

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.

user990423
  • 1,397
  • 2
  • 12
  • 32
Estarossa
  • 585
  • 4
  • 21

2 Answers2

1

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>
theadriangreen
  • 2,218
  • 1
  • 14
  • 14
  • Could you please be more specific? how do I use this rule? – Estarossa Jun 15 '15 at 22:12
  • Sorry for the report but i keep getting 404.4 error too – Estarossa Jun 16 '15 at 09:05
  • This rule will forward from .azurewebsites.net/static/path-to-file to https://blobtest.blob.core.windows.net/static/path-to-file . Obviously the file would have to exist in your blob storage at the expected path. – theadriangreen Jun 17 '15 at 18:11
  • 1
    I know what you mean but it exists, the link is working. If i change rewrite to redirect it works. When the type is rewrite I receive an error telling me that i am missing a handler which i added to the web config but no luck. – Estarossa Jun 28 '15 at 15:38
0

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>
Dinny
  • 59
  • 6