隐藏Azure Blob网址 [英] Hide Azure Blob Url
问题描述
我在公共Azure blob容器中存储了大量文件,所有文件都通过ASP.NET MVC Web应用程序中的HTML直接引用.例如,指向Blob存储中的图像之一的路径如下所示:
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
我想避免在HTML源代码中显示存储帐户名称,而不是:
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"/>
我更喜欢使用这个:
<img src="/images/logo.png"/>
我想避免设置MVC路由并使用blob API将文件加载到响应流中,因此我认为web.config解决方案可能是最简单的解决方案,即
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>
问题:考虑到任何页面一次最多可以加载30张以上的图像,这是最有效的方法吗?还是我出于对性能提升的考虑而应该仅使用公共Blob URL?
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?
推荐答案
我找到了Microsoft动手实验室,他们在其中推荐了web.config URL重写规则选项:
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)
(代码段-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>
注意:URL重写是拦截传入的Web请求并将请求重定向到其他资源的过程.URL重写规则告诉重写引擎何时需要重定向请求以及将请求重定向到何处重写规则由两个字符串组成:要在请求的URL中查找的模式(通常使用正则表达式),以及用于替换该模式的字符串(如果找到).有关更多信息,请参见ASP中的URL重写. NET."
这篇关于隐藏Azure Blob网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!