/// <inheritdoc /> public override string RouteUrl(UrlRouteContext routeContext) { if (routeContext == null) { throw new ArgumentNullException(nameof(routeContext)); } var valuesDictionary = routeContext.Values as RouteValueDictionary ?? GetValuesDictionary(routeContext.Values); var endpoints = _routeValuesBasedEndpointFinder.FindEndpoints( new RouteValuesBasedEndpointFinderContext() { RouteName = routeContext.RouteName, ExplicitValues = valuesDictionary, AmbientValues = AmbientValues }); var successfullyGeneratedLink = _linkGenerator.TryGetLink( ActionContext.HttpContext, endpoints, valuesDictionary, AmbientValues, out var link); if (!successfullyGeneratedLink) { return(null); } return(GenerateUrl(routeContext.Protocol, routeContext.Host, link, routeContext.Fragment)); }
public void RouteUrlWithUrlRouteContext_ReturnsExpectedResult() { // Arrange var urlHelper = CreateUrlHelperWithDefaultRoutes(); var routeContext = new UrlRouteContext() { RouteName = "namedroute", Values = new { Action = "newaction", Controller = "home2", id = "someid" }, Fragment = "somefragment", Host = "remotetown", Protocol = "ftp" }; // Act var url = urlHelper.RouteUrl(routeContext); // Assert Assert.Equal("ftp://remotetown/app/named/home2/newaction/someid#somefragment", url); }
/// <inheritdoc /> public override string RouteUrl(UrlRouteContext routeContext) { if (routeContext == null) { throw new ArgumentNullException(nameof(routeContext)); } var valuesDictionary = routeContext.Values as RouteValueDictionary ?? GetValuesDictionary(routeContext.Values); var successfullyGeneratedLink = _linkGenerator.TryGetLink( new LinkGeneratorContext() { Address = new Address(routeContext.RouteName), SuppliedValues = valuesDictionary, AmbientValues = AmbientValues }, out var link); if (!successfullyGeneratedLink) { return(null); } return(GenerateUrl(routeContext.Protocol, routeContext.Host, link, routeContext.Fragment)); }
/// <inheritdoc /> #pragma warning disable CA1055 // URI-like return values should not be strings public virtual string RouteUrl(UrlRouteContext routeContext) #pragma warning restore CA1055 { if (routeContext == null) { throw new ArgumentNullException(nameof(routeContext)); } routeContext.Values = AddApiVersionRouteValueIfNecessary(routeContext.Values); return(Url.RouteUrl(routeContext)); }
/// <inheritdoc /> public override string?RouteUrl(UrlRouteContext routeContext) { if (routeContext == null) { throw new ArgumentNullException(nameof(routeContext)); } var valuesDictionary = routeContext.Values as RouteValueDictionary ?? GetValuesDictionary(routeContext.Values); var virtualPathData = GetVirtualPathData(routeContext.RouteName, valuesDictionary); return(GenerateUrl(routeContext.Protocol, routeContext.Host, virtualPathData, routeContext.Fragment)); }
public override string?RouteUrl(UrlRouteContext routeContext) { if (routeContext == null) { throw new ArgumentNullException(nameof(routeContext)); } var path = _linkGenerator.GetPathByRouteValues( ActionContext.HttpContext, routeContext.RouteName, routeContext.Values, fragment: routeContext.Fragment == null ? FragmentString.Empty : new FragmentString("#" + routeContext.Fragment)); return(GenerateUrl(routeContext.Protocol, routeContext.Host, path)); }
/// <inheritdoc /> public override string RouteUrl(UrlRouteContext routeContext) { if (routeContext == null) { throw new ArgumentNullException(nameof(routeContext)); } var valuesDictionary = routeContext.Values as RouteValueDictionary ?? GetValuesDictionary(routeContext.Values); var pathData = GetVirtualPathData(routeContext.RouteName, valuesDictionary); if (pathData is AbsolutPathData) { //we don't support changing protocol for subdomain return(GenerateUrl(((AbsolutPathData)pathData).Protocol, ((AbsolutPathData)pathData).Host, pathData, routeContext.Fragment)); } return(GenerateUrl(routeContext.Protocol, routeContext.Host, pathData, routeContext.Fragment)); }
/// <inheritdoc /> public override string RouteUrl(UrlRouteContext routeContext) { if (routeContext == null) { throw new ArgumentNullException(nameof(routeContext)); } var valuesDictionary = routeContext.Values as RouteValueDictionary ?? GetValuesDictionary(routeContext.Values); var successfullyGeneratedLink = _linkGenerator.TryGetLink( ActionContext.HttpContext, routeContext.RouteName, valuesDictionary, out var link); if (!successfullyGeneratedLink) { return(null); } return(GenerateUrl(routeContext.Protocol, routeContext.Host, link, routeContext.Fragment)); }
public void Page_WithName_Works() { // Arrange UrlRouteContext actual = null; var routeData = new RouteData { Values = { { "page", "ambient-page" }, } }; var actionContext = new ActionContext { RouteData = routeData, }; var urlHelper = CreateMockUrlHelper(actionContext); urlHelper.Setup(h => h.RouteUrl(It.IsAny <UrlRouteContext>())) .Callback((UrlRouteContext context) => actual = context); // Act urlHelper.Object.Page("/TestPage"); // Assert urlHelper.Verify(); Assert.NotNull(actual); Assert.Null(actual.RouteName); Assert.Collection(Assert.IsType <RouteValueDictionary>(actual.Values), value => { Assert.Equal("page", value.Key); Assert.Equal("/TestPage", value.Value); }); Assert.Null(actual.Host); Assert.Null(actual.Protocol); Assert.Null(actual.Fragment); }
/// <inheritdoc /> public abstract string RouteUrl(UrlRouteContext routeContext);
public override string RouteUrl(UrlRouteContext routeContext) { throw new NotImplementedException(); }