Home
Manage Your Code
Snippet: Get base url for a web app. (C#)
Title: Get base url for a web app. Language: C#
Description: Get the base url programmatically, so you can use it to create fully qualified urls in your web app. Views: 2393
Author: Aaron Crandall Date Added: 3/16/2007
Copy Code  
1/// <summary>

2/// Returns the base application url (such as "http://localhost/myweb/").

3/// The url will have a trailing forward slash.

4/// </summary>

5/// <returns></returns>

6private string getBaseUrl(HttpRequest request)
7{
8	StringBuilder url = new StringBuilder();
9	url.Append(request.Url.Scheme);
10	url.Append("://");
11	url.Append(request.Url.Host);
12	if(request.Url.Port != 80)
13	{
14		url.Append(":");
15		url.Append(request.Url.Port);
16	}
17	url.Append(request.ApplicationPath);
18	url.Append("/");
19	return url.ToString();
20}