Getting relative virtual path from physical path

前端 未结 4 810
青春惊慌失措
青春惊慌失措 2020-11-29 04:50

How can I get the relative virtual path from the physical path in asp.net? The reverse method is like below:

Server.MapPath(\"Virtual Path Here\");
         


        
4条回答
  •  悲哀的现实
    2020-11-29 05:41

    Request.ServerVariables["APPL_PHYSICAL_PATH"]
    

    is fine, but not always. It is available only if there's a HTTP request.

    On the other hand the call

    HostingEnvironment.ApplicationPhysicalPath
    

    is always available.

提交回复
热议问题