我有一个MVC应用程序和部署到一个服务器,我只有ftp访问,该应用程序的名称是test.foo.com。有一个后台,用户可以将图片上传到应用程序中。一切都很好。代码如下:
//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是如何配置的。
发布于 2013-01-01 07:06:29
Server.MapPath("~")指向ASP.NET应用程序配置为在其下运行的物理根文件夹。所以我猜在IIS中有一些配置,所以test.foo.com和foo.com实际上都指向同一个应用程序。如果您无法访问服务器来检查这一点,除了联系您的主机提供商并询问有关如何设置这些域名以及它们映射到哪些应用程序的更多详细信息之外,您没有什么可做的。
https://stackoverflow.com/questions/14105108
复制相似问题