隐藏Azure Blob网址

编程入门 行业动态 更新时间:2024-10-13 22:21:22
本文介绍了隐藏Azure Blob网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在公共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/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/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/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:

动手实验:可维护的Azure网站:管理变更和规模(2014年7月16日)

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="[YOUR-STORAGE-ACCOUNT].blob.core.windows/images/{R:1}"></action> </rule> </rules> </rewrite>

注意:URL重写是拦截传入的Web请求并将请求重定向到其他资源的过程.URL重写规则告诉重写引擎何时需要重定向请求以及将请求重定向到何处重写规则由两个字符串组成:要在请求的URL中查找的模式(通常使用正则表达式),以及用于替换该模式的字符串(如果找到).有关更多信息,请参见ASP中的URL重写. NET."

更多推荐

隐藏Azure Blob网址

本文发布于:2023-10-31 13:29:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1546224.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:网址   Azure   Blob

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!