The following example returns the physical path of the virtual directory that contains the specified Web site.
FilePath = Server.MapPath("MyWebSite");除了这个方法还有别的好方法么?

解决方案 »

  1.   

    在 http://www.mysite.com/page/subfolder1/subfolder2/1.aspx 中调用 Server.MapPath() 或者 其他方法 怎样能得到"C:\intepub\wwwroot\mysite\"这个根物理路径 或者 得到 "http://www.mysite.com/" ??? 我的目的是为了解决这样一个问题:
    如果 在 http://www.mysite.com/page/subfolder1/subfolder2/1.aspx  中,怎样访问位于站点根目录中的资源?
      

  2.   

    获取站点URL根路径的方法:Dim AbsUri As String = Request.Url.AbsoluteUri
    Dim RawUrl As String = Request.RawUrl
    Dim RootUrl As String
    RootUrl = Left(AbsUri, Len(AbsUri) - Len(RawUrl)) & Request.ApplicationPath上述最后一行的“ & Request.ApplicationPath”用于虚拟目录
      

  3.   

    Request.Url.Host  can get it
      

  4.   

    RegistryKey n = Registry.LocalMachine.OpenSubKey("SYSTEM\\ControlSet001\\Services\\W3SVC\\Parameters\\Virtual Roots");
    Label2.Text = (string)n.GetValue("/");
    记得把后面的数字去掉就搞定了。
      

  5.   

    在Web.config文件中:
    <appSettings>
      <add key="TreeFile" value="E:\\Admin\\AdminEnd\\XML\\" />
      <add key="WebAdminID" value="1" />
    </appSettings>在程序中:
    ConfigurationSettings.AppSettings["TreeFile"]
      

  6.   

    物理路径: request.PhysicalApplicationPathRUL路径:request.ApplicationPath