简体   繁体   English

IIS根路径与虚拟目录的路径

[英]IIS Root Path vs Path of virtual directory

I am using code that will get the root path 我正在使用将获取根路径的代码

return HttpContext.Current.Server.MapPath(@"\Schedules\");

This works great when my site is installed as a fully fledged web app. 当我的网站安装为完整的Web应用程序时,此功能非常有用。 but when its installed as a virtual directory it breaks, because it is looking for files in root folder, and not in \\virtualdirectorypath folder. 但是当将其安装为虚拟目录时,它会中断,因为它正在寻找根文件夹中的文件,而不是\\ virtualdirectorypath文件夹中的文件。

Is there a way I can change the code to look for files from the virtual directory root, but also so it won't break if the app is installed as a fully fledged website? 有没有一种方法可以更改代码以从虚拟目录根目录中查找文件,但是如果将应用程序安装为完整的网站,它也不会损坏?

尝试这个:

return HttpContext.Current.Server.MapPath(@"~/Schedule/");

使用〜根运算符。

Server.MapPath("~"); // path of root of web application.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM