开发者

Find the URL of an application

I am Working on an asp.net c# application.

I wish to find the url of the application.开发者_开发问答 For example, my application is NRCME I want to return http://localhost:4833/NRCME/ when running locally. From the server I want to return

http://servername/NRCME/


You can find information about the url in Request.Url. It will include the file name by default but you can easily remove that like this:

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


Here's everything you need to know: http://www.cambiaresearch.com/c4/dfdb20ae-b335-48ae-a201-f2a5a8329342/How-Do-I-Get-Paths-and-URL-fragments-from-the-HttpRequest-object.aspx


I came up with my own answer.

        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();
        }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜