2012-12-31 93 views
1

我有一个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。

+0

您需要了解IIS的配置方式。主机名绑定不会影响应用程序根目录在文件系统中的位置。 –

+0

我需要在IIS配置中查看哪些内容? – DarthVader

+0

应用程序主目录是重要的。你不能通过FTP查看,所以问问你的主机。 –

回答

1

Server.MapPath("~")指向ASP.NET应用程序配置为在其下运行的物理根文件夹。所以我猜想在IIS中有一些配置,因此test.foo.comfoo.com实际上都指向同一个应用程序。如果您无法访问服务器进行检查,除联系您的托管服务提供商之外,您可以做的事情不多,并要求提供有关如何设置这些域以及它们映射到的应用程序的更多详细信息。

+0

谢谢。我会联系主机提供商。 – DarthVader

相关问题