• How to get application name from HttpContext

    Posted on May 31, 2012 by in Dotnet Tips & Tricks, Tips & Tricks

    public static string GetApplicationName()
            {
                System.Web.HttpRequest httprequest = HttpContext.Current.Request;
                string applicationName = String.Empty;
                try
                {
                    if (httprequest != null)
                    {
                        if (httprequest.Url != null
                            && (httprequest.Url.AbsolutePath) != String.Empty)
                        {
                            string del = string.Empty;
    
                            if (httprequest.Url.AbsolutePath.Contains("/"))
                            {
                                del = "/";
                                string[] splitUrl = httprequest.Url.AbsolutePath.Split(del.ToCharArray());
                                if (splitUrl.Length > 1)
                                {
                                    applicationName = splitUrl[1].ToString();
                                }
                            }
                        }
                    }
                }
                catch
                {
                    applicationName = Environment.MachineName;
                }
                return applicationName;
            }
    Be Sociable, Share!
      Post Tagged with

    Written by

    View all articles by

    Email : [email protected]

    Leave a Reply