Reputation: 55032
I have an MVC app and deployed to a Server, which i have only ftp access, the name of the app is test.foo.com
. There is a backend which users upload pictures to the app. Everything works great. The code is as follow:
//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));
and here the fileuploadhelper which returns the uploaded path:
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;
}
}
Well this code works fine.
The problem is when this app was deployed to foo.com
. Pictures are still being uploaded to test.foo.com
App_Data folder.
ie: I am uploading an image from foo.com and image is being stored under :
c:\inetpub\wwwroot\test.foo.com\App_Data
whereas it should go to
c:\inetpub\wwwroot\foo.com\App_Data
Why is this happening?
I dont know how the server, IIS was configured.
Upvotes: 2
Views: 4511
Reputation: 1038790
Server.MapPath("~")
is pointing to the physical root folder of where the ASP.NET application is configured to run under. So I guess there's some configuration in IIS so that both test.foo.com
and foo.com
are actually pointing to the same application. If you do not have access to the server to check this out, there's not much you could do other than contacting your hosting provider and ask for more details about how those domains are setup and which applications they are mapped to.
Upvotes: 2