The method UrlHelper.GenerateUrl() is located in System.Web.Mvc.UrlHelper
I need a different implementation that would affect everything from Url.Action() to Html.BeginForm().
This is the current .NET implementation:
[SuppressMessage("Microsoft.Design", "CA1055:UriReturnValuesShouldNotBeStrings", Justification = "As the return value will used only for rendering, string return value is more appropriate.")]
public static string GenerateUrl(string routeName, string actionName, string controllerName, string protocol, string hostName, string fragment, RouteValueDictionary routeValues, RouteCollection routeCollection, RequestContext requestContext, bool includeImplicitMvcValues) {
string url = GenerateUrl(routeName, actionName, controllerName, routeValues, routeCollection, requestContext, includeImplicitMvcValues);
if (url != null) {
if (!String.IsNullOrEmpty(fragment)) {
url = url + "#" + fragment;
}
if (!String.IsNullOrEmpty(protocol) || !String.IsNullOrEmpty(hostName)) {
Uri requestUrl = requestContext.HttpContext.Request.Url;
protocol = (!String.IsNullOrEmpty(protocol)) ? protocol : Uri.UriSchemeHttp;
hostName = (!String.IsNullOrEmpty(hostName)) ? hostName : requestUrl.Host;
string port = String.Empty;
string requestProtocol = requestUrl.Scheme;
if (String.Equals(protocol, requestProtocol, StringComparison.OrdinalIgnoreCase)) {
port = requestUrl.IsDefaultPort ? String.Empty : (":" + Convert.ToString(requestUrl.Port, CultureInfo.InvariantCulture));
}
url = protocol + Uri.SchemeDelimiter + hostName + port + url;
}
}
return url;
}
I know that its possible to override static methods using delegates, but that won't allow all of method calls to the same method from different classes use my implementation instead of the default one.