Server.MapPath从root返回两个文件夹

pet*_*ski 7 c# asp.net iis

我是这样做的:

HttpContext.Current.Server.MapPath(@"~\~\~\Content\")
Run Code Online (Sandbox Code Playgroud)

我知道'.' 是为了项目的根,但如何回几个文件夹?

Rup*_*Rup 13

如果您确实需要祖父路径,可以使用Path.GetDirectoryName()以下命令从根路径获取:

string root = Server.MapPath("~");
string parent = Path.GetDirectoryName(root);
string grandParent = Path.GetDirectoryName(parent);
Run Code Online (Sandbox Code Playgroud)

但是你的网络应用很可能没有阅读或写作的权限 - 我不确定你将用它做什么.

  • root,parent和grandParent都返回相同的路径.为什么? (2认同)