Метод UrlHelper.GenerateUrl () находится в System.Web.Mvc.UrlHelper
Мне нужна другая реализация, которая затрагивала бы все: от Url.Action () до Html.BeginForm ().
Это текущая реализация .NET:
[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;
}
Я знаю, что возможно переопределить статические методы с использованием делегатов, но это не позволит всем вызовам методов одного и того же метода из разных классов использовать мою реализацию вместо стандартной.