由 D:\a\b\c\bin\Debug\1.exe;
怎么得到:D:\a\b\c\;  

解决方案 »

  1.   

    Response.Write("<br>服务器实际路径是:" + Request.PhysicalPath);
      

  2.   

    System.AppDomain.CurrentDomain.BaseDirectory;
    这个行不?
      

  3.   

     /// <summary>
            /// 获得物理路径
            /// </summary>
            /// <param name="a">路径</param>
            /// <returns>物理路径</returns>
            public static string GetFullPath(string a)
            {
                string AppDir = System.AppDomain.CurrentDomain.BaseDirectory;
                if (a.IndexOf(":") < 0)
                {
                    string str = a.Replace("..\\", "");
                    if (str != a)
                    {
                        int Num = (a.Length - str.Length) / ("..\\").Length + 1;
                        for (int i = 0; i < Num; i++)
                        {
                            AppDir = AppDir.Substring(0, AppDir.LastIndexOf("\\"));
                        }
                        str = "\\" + str;                }
                    a = AppDir + str;
                }
                return a;
            }
      

  4.   

     /// <summary>
            /// 获得物理路径
            /// </summary>
            /// <param name="a">路径</param>
            /// <returns>物理路径</returns>
            public static string GetFullPath(string a)
            {
                string AppDir = System.AppDomain.CurrentDomain.BaseDirectory;
                if (a.IndexOf(":") < 0)
                {
                    string str = a.Replace("..\\", "");
                    if (str != a)
                    {
                        int Num = (a.Length - str.Length) / ("..\\").Length + 1;
                        for (int i = 0; i < Num; i++)
                        {
                            AppDir = AppDir.Substring(0, AppDir.LastIndexOf("\\"));
                        }
                        str = "\\" + str;                }
                    a = AppDir + str;
                }
                return a;
            }
      

  5.   

    用这个
    System.AppDomain.CurrentDomain.BaseDirectory;
      

  6.   

    会得到D:\a\b\c\bin\Debug,不是D:\a\b\c\
      

  7.   

    HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString()
      

  8.   

    System.Web.HttpContext.Current.Request.PhysicalApplicationPath