Skip to content

Instantly share code, notes, and snippets.

@leegould
Created February 17, 2012 12:50
Show Gist options
  • Save leegould/1853248 to your computer and use it in GitHub Desktop.
Save leegould/1853248 to your computer and use it in GitHub Desktop.
HttpRequest extension method - GetSiteUrl
using System.Web;
namespace www.Helper
{
public static class HttpRequestExtensions
{
/// <summary>
/// Extension method to retrieve the site url.
/// e.g.
/// http://localhost:1234/ or
/// http://someremoteserver/virtualdir/
/// </summary>
/// <param name="request"/>The site url with application path</param>
public static string GetSiteUrl(this HttpRequest request)
{
return request.Url.Scheme + @"://" + request.Url.Authority +
(request.ApplicationPath.Length > 1 ? request.ApplicationPath + "/" : request.ApplicationPath);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment