Web角色的本地存储URI [英] Web Role local storage URI

查看:255
本文介绍了Web角色的本地存储URI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个本地存储文件夹,名为 TempStore ,建立在我的Web角色的实例。

I have a local storage folder, called TempStore, set up on my Web Role instances.

是否有可能从我的本地存储文件公开作为一个URI?

例如:

http://myapplication.cloudapp.net/TempStore/helloworld.jpg

我明白,我可以用斑点这一点,但我会preFER在这种情况下使用本地存储。

I understand that I could use blobs for this, but I would prefer to use local storage in this case.

推荐答案

有。不过,我真不明白这样做的原因是什么?我看到的唯一原因是一些误解或不完全了解Windows Azure平台服务(存储,云服务/网络角色)的功能

There is. However I really do not understand the reason for doing this? The only reason I see is some misunderstanding or not fully understanding the capabilities of the Windows Azure Platform Services (Storage, Cloud Service / Web Roles).

您必须知道本地存储是不是角色实例之间的同步。此外,如果硬件故障发生时,角色愈合进程将实例化一个全新的虚拟机从您的云服务包清新的形象。这将导致一个空空如也的本地存储资源。 Windows Azure的负载平衡器(在你的web和辅助角色,更多的这里)使用循环算法。也就是说即使有一个要求用户上传文件到你的Web角色。下一个请求(即你可能会想显示preVIEW)可能会去一个没有用户上传想法另一个实例。

You have to know that local storage is not synced between role instances. Also if hardware failure happens, a role healing process will instantiate an entirely new VM with fresh image from your cloud service package. This will lead to an absolutely empty local storage resource. Windows Azure Load Balancer (the thing that sits in front of your web and worker roles, more here) uses Round Robin algorithm. Meaning that even if with one request user uploads file to your web role. The next request (that you will probably want to show preview) might go to another instance that has no idea of user uploaded.

如果,知道所有这些事实后,仍想搬起石头砸自己的脚这里是解决方案:

If, after knowing all these facts, you still want to "shoot yourself in the foot" here is the solution:


  • 的VirtualPathProvider

  • 注册它所需的公共URL路径

  • 使用<一个href=\"http://msdn.microsoft.com/en-us/library/microsoft.windowsazure.serviceruntime.roleenvironment.getlocalresource.aspx\"相对=nofollow> RoleEnvironment.GetLocalResource 方法在你的VPP获得完整路径本地存储资源

  • 请不要责怪任何人,当你意识到这是一个错误;)

  • Implement VirtualPathProvider
  • register it for desired public URL Path
  • Use the RoleEnvironment.GetLocalResource method in your VPP to obtain the full path to the local storage resource
  • don't blame anyone else when you realize this was a mistake ;)

这篇关于Web角色的本地存储URI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆