Web Role local storage URI

拜拜、爱过 提交于 2019-12-11 10:32:46

问题


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

Is it possible to expose files as a URI from my local storage?

E.g:

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

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


回答1:


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

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:

  • 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 ;)


来源:https://stackoverflow.com/questions/17874648/web-role-local-storage-uri

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!