Server.MapPath to go two folder back from root

后端 未结 5 1089
鱼传尺愫
鱼传尺愫 2020-12-30 12:12

Here is how I do it:

HttpContext.Current.Server.MapPath(@\"~\\~\\~\\Content\\\")

HI know that \'.\' is for the root of the project, but how

5条回答
  •  囚心锁ツ
    2020-12-30 12:25

    Start with the root of your site with ~ and specify the full path: ~/Archive/Content.

    You can't go back above site root because of security restrictions, see also this article from other solutions.

    IIS purposefully prevents serving up content directly that is outside of the site path. However, you can create a virtual directory in IIS and have ISAPI Rewrite point to that. For example, create a virtual directory called /staticfiles that points to c:\test\data\static-files. As far as IIS is concerned, that's directly off of the root of the site in a folder called /staticfiles.

提交回复
热议问题