我有一個MVC應用程序並部署到服務器,我只有ftp訪問,應用程序的名稱是test.foo.com
。有一個用戶上傳圖片到應用程序的後端。一切都很好。其代碼如下:Server.MapPath返回不正確的路徑
//in web config this is the value
<add key="NewsImagesPath" value="~/App_Data/NewsImages/" />
// this is in controller
private static readonly string news_images_path = ConfigurationManager.AppSettings["NewsImagesPath"];
// in the method
String uploadedFile = fileUploadHelper.UploadFile(file, Server.MapPath(news_images_path));
這裏的fileuploadhelper返回上傳的路徑:
public class FileUploadHelper
{
public string UploadFile(HttpPostedFileBase file, string path)
{
if (file != null && file.ContentLength > 0)
{
FileInfo fileInfo = new FileInfo(file.FileName);
string fileName = Guid.NewGuid() + fileInfo.Extension;
var uploadPath = Path.Combine(path, fileName);
file.SaveAs(uploadPath);
return uploadPath;
}
return null;
}
}
嗯,這代碼工作正常。
問題是當這個應用程序被部署到foo.com
。照片仍在上傳到test.foo.com
App_Data文件夾。
即:我上傳的foo.com和圖像的圖像被存儲在:
c:\inetpub\wwwroot\test.foo.com\App_Data
,而應該去
c:\inetpub\wwwroot\foo.com\App_Data
這究竟是爲什麼?
我不知道如何配置服務器,IIS。
您需要了解IIS的配置方式。主機名綁定不會影響應用程序根目錄在文件系統中的位置。 –
我需要在IIS配置中查看哪些內容? – DarthVader
應用程序主目錄是重要的。你不能通過FTP查看,所以問問你的主機。 –