我已經在ASP.NET MVC3項目中爲上傳文件編寫了一些代碼。我不是將文件存儲在數據庫中,而是將文件上傳到文件系統,並將路徑存儲在數據庫中。ASP.NET文件上傳在Windows Azure中不起作用
上傳的代碼如下: -
if (file != null && file.ContentLength > 0)
{
if (path == null)
{
throw new ArgumentNullException("path cannot be null");
}
string pFileName = PrefixFName(file.FileName);
String relpath = String.Format("{0}/{1}", path, pFileName);
try
{
file.SaveAs(Server.MapPath(relpath));
return pFileName;
}
catch (HttpException e)
{
throw new ApplicationException("Cannot save uploaded file", e);
}
}
保存文件後我已經使用圖像標記,圖像中的幾個觀點。我的代碼在本地運行良好。但是當我在windowsazure.com上託管這個網站時,所有的東西都在運行,但是文件上傳。
我該如何擺脫這種情況?請幫忙。
是應用程序運行的'Website'或'雲Service'?還有你的應用程序運行多少個實例? –
什麼不起作用?該文件沒有保存,你不能訪問它,它會拋出一個異常...? – Kenneth
@ Gaurav Mantri,我的網站作爲網站運行,只有一個實例正在運行。僅供參考我已將所有圖像保存在「〜/ Content/Images/MyFolder」 –