Created
February 17, 2012 12:50
-
-
Save leegould/1853248 to your computer and use it in GitHub Desktop.
HttpRequest extension method - GetSiteUrl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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