找到应用程序的URL

时间:2011-02-23 22:28:36

标签: c# asp.net

我正在使用asp.net c#应用程序。

我希望找到该应用程序的网址。例如,我的应用程序是NRCME我想在本地运行时返回http://localhost:4833/NRCME/。从我想要返回的服务器

http://servername/NRCME/

3 个答案:

答案 0 :(得分:0)

您可以在Request.Url中找到有关该网址的信息。它默认包含文件名,但您可以轻松删除它:

Request.Url.AbsoluteUri.Replace(Request.Url.LocalPath, "")

答案 1 :(得分:0)

答案 2 :(得分:0)

我想出了自己的答案。

        string _ApplicationPath = GetCurrentPageName();
        string _URL = Request.Url.ToString();
        string _ReturnString;
        Int32 _Position = _URL.IndexOf(_ApplicationPath);

        _ReturnString = _URL.Replace(_ApplicationPath, "");

        return _ReturnString;

    }
                 public static string GetCurrentPageName()
        {
            string sPath = System.Web.HttpContext.Current.Request.Url.AbsolutePath;
            System.IO.FileInfo oInfo = new System.IO.FileInfo(sPath);
            string sRet = oInfo.Name;
            return sRet.ToLower();
        }