如何从ASP.NET中的子域应用程序访问主域目录

问题描述:

我有主域名www.abc.com和子域名crm.abc.com我想将图像从子域名上传到主domian目录 - www.abc.com/images/users



我的尝试:



string foloderLocation = Server.MapPath(〜/ images / users / + filename;

I have main domain www.abc.com and subdomain crm.abc.com I want to upload an image from subdomain to main domian directory -- www.abc.com/images/users

What I have tried:

string foloderLocation = Server.MapPath("~/images/users/" +filename);

最简单的选择是使用IIS在CRM站点中添加指向主站点上文件夹的虚拟目录。然后,您可以使用 MapPath 来获取文件夹的物理路径:

The simplest option would be to use IIS to add a virtual directory in the CRM site pointing to the folder on the main site. You could then use MapPath to get the physical path of the folder:
string folderLocation = Server.MapPath("~/main-site-images/users/" + filename);



如果由于某种原因无法做到这一点,那么你需要指定物理路径直。您可能希望将它放在配置文件中,这样您就不必在每次路径更改时重新编译。


If you can't do that for some reason, then you'll need to specify the physical path directly. You'll probably want to put it in your config file, so that you don't have to recompile every time the path changes.

string folderLocation = System.IO.Path.Combine(WebConfigurationManager.AppSettings["mainSiteImagesPath"], "users", filename);