有没有办法在Azure上部署Web应用程序而不修改将数据保存到磁盘的Upload方法?
在上传方法中,我将数据保存在磁盘上:
var imgPath = Url.Content(String.Format("~/Content/PersonImg/{0}", fileName));
String filePath = HostingEnvironment.MapPath(imgPath);
答案 0 :(得分:2)
如果您要在 Windows Azure Website
中部署代码,那么上传代码应该可行,但我看到有人使用Server.MapPath
代替HostingEnvironment.MapPath
。但是,如果您在 Windows Azure Cloud Service
中部署代码,则上述代码将无效。如果是云服务,则需要使用Local Storage
。
话虽如此,我认为你应该避免将文件存储在服务器本身上。如另一个答案所述,VM中的存储不是持久的。此外,对于Windows Azure网站,您获得的磁盘空间量有限。如其他答案中所述,您应该查看Windows Azure Blob Storage
来存储这些文件。
答案 1 :(得分:1)
如果要将Web应用程序部署到云,则应使用Azure存储来存储文件。云服务的磁盘不是永久性的。
这是一些帮助: http://www.windowsazure.com/en-us/documentation/services/storage/