Server.MapPath(“.”), Server.MapPath(“~”), Server.MapPath(@“\”), Server.MapPath(“/”). What is the difference?

后端 未结 3 463
谎友^
谎友^ 2020-11-21 23:59

Can anyone explain the difference between Server.MapPath(\".\"), Server.MapPath(\"~\"), Server.MapPath(@\"\\\") and Server.MapPa

3条回答
  •  醉酒成梦
    2020-11-22 00:15

    Just to expand on @splattne's answer a little:

    MapPath(string virtualPath) calls the following:

    public string MapPath(string virtualPath)
    {
        return this.MapPath(VirtualPath.CreateAllowNull(virtualPath));
    }
    

    MapPath(VirtualPath virtualPath) in turn calls MapPath(VirtualPath virtualPath, VirtualPath baseVirtualDir, bool allowCrossAppMapping) which contains the following:

    //...
    if (virtualPath == null)
    {
        virtualPath = VirtualPath.Create(".");
    }
    //...
    

    So if you call MapPath(null) or MapPath(""), you are effectively calling MapPath(".")

提交回复
热议问题