我有一个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查看,所以问问你的主机。 –