代码之家  ›  专栏  ›  技术社区  ›  rlb.usa

ASP.NET从URL获取物理文件路径

  •  7
  • rlb.usa  · 技术社区  · 15 年前

    有没有方法从ASP.NET的URL获取物理文件路径?

    scenerio:我有一个应用程序在两台服务器上,但现在它将在更多服务器上运行,并且每个服务器都将它放在不同的物理文件路径中。现在我要做的是:

    //for server 1
    if (Request.Url.GetLeftPart(UriPartial.Path).Contains(".com"))
     { Application["StoreFilesPath"] = "E:\\Data\\rootsite\\f1\\appsite\\Upload\\"; }
    
    //for server 2
    if (Request.Url.GetLeftPart(UriPartial.Path).Contains(".net"))
     { Application["StoreFilesPath"] = "E:\\Web\\rootsite2\\f34\\abc\\ghi\\appsite\\Upload\\"; }
    

    但我需要做的是这样的事情:

    //for all servers
    Application["StoreFilesPath"] = getPhysicalFilePath() +"\\Upload\\";
    

    我该怎么做?

    3 回复  |  直到 11 年前
        1
  •  7
  •   Oded    15 年前

    HttpServerUtility.MapPath Application Session

        2
  •  4
  •   m.edmondson    15 年前

    Server.MapPath ( "/" ); HttpContext.Current.Server.MapPath ( "/" );

        3
  •  3
  •   Piotr Stulinski    11 年前

    HostingEnvironment.MapPath("/");
    
    推荐文章