Hide Azure Blob Url

2020-03-26 11:34发布

I have a large amount of files stored in a public Azure blob container, all of which are referenced directly via the HTML in my ASP.NET MVC web application. As an example a path to one of the images in blob storage looks like so:

//<my-storage-account-name>.blob.core.windows.net/public/logo.png

I want to avoid displaying my storage account name in my HTML source code so rather than:

<img src="//<my-storage-account-name>.blob.core.windows.net/public/logo.png"/> 

I'd prefer to use this:

<img src="/images/logo.png"/> 

I want to avoid setting up an MVC route and using the blob API to load the file into the response stream so thought a web.config solution might be the simplest solution, i.e.

<rule name="Image Redirect" stopProcessing="true">
    <match url="^images/(.*)$" ignoreCase="false" />
    <action type="Redirect" url="//<my-storage-account-name>.blob.core.windows.net/public/{R:1}" redirectType="Permanent" />
</rule>

QUESTION: Is this the most efficient method given that any page could be loading 30+ images at a time? Or should I just use the public blob URL despite my concerns for performance gains?

标签: blob
1条回答
欢心
2楼-- · 2020-03-26 12:23

I found a Microsoft Hands-on Lab where they recommend the web.config URL rewrite rule option:

Hands on Lab: Maintainable Azure Websites: Managing Change and Scale (July 16, 2014)

(Code Snippet - WebSitesInProduction - Ex4 - UrlRewriteRule)

<system.webServer>
    <rewrite>
        <rules>
            <rule name="redirect-images" stopProcessing="true">
                <match url="img/(.*)"/>
                <action type="Redirect" url="http://[YOUR-STORAGE-ACCOUNT].blob.core.windows.net/images/{R:1}"></action>
            </rule>
        </rules>
    </rewrite>

"Note: URL rewriting is the process of intercepting an incoming Web request and redirecting the request to a different resource. The URL rewriting rules tells the rewriting engine when a request needs to be redirected, and where should they be redirected. A rewriting rule is composed of two strings: the pattern to look for in the requested URL (usually, using regular expressions), and the string to replace the pattern with, if found. For more information, see URL Rewriting in ASP.NET."

查看更多
登录 后发表回答