隐藏 Azure Blob Url

Hide Azure Blob Url

我有大量文件存储在 public Azure blob 容器中,所有这些文件都通过我的 ASP.NET MVC Web 应用程序中的 HTML 直接引用。例如,blob 存储中其中一张图像的路径如下所示:

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

我想避免在我的 HTML 源代码中显示我的存储帐户名称,而不是:

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

我更愿意使用这个:

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

我想避免设置 MVC 路由并使用 blob API 将文件加载到响应流中,因此认为 web.config 解决方案可能是最简单的解决方案,即

<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>

问题:考虑到任何页面都可以一次加载 30 多张图片,这是最有效的方法吗?或者我应该只使用 public blob URL 尽管我担心性能提升?

我找到了一个 Microsoft 动手实验室,他们在其中推荐 web.config URL 重写规则选项:

Hands on Lab: Maintainable Azure Websites: Managing Change and Scale(2014 年 7 月 16 日)

(代码片段 - 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."