Ejemplo n.º 1
0
        /// <inheritdoc />
        public override string Action(UrlActionContext urlActionContext)
        {
            if (urlActionContext == null)
            {
                throw new ArgumentNullException(nameof(urlActionContext));
            }

            var valuesDictionary = GetValuesDictionary(urlActionContext.Values);

            if (urlActionContext.Action == null)
            {
                if (!valuesDictionary.ContainsKey("action") &&
                    AmbientValues.TryGetValue("action", out var action))
                {
                    valuesDictionary["action"] = action;
                }
            }
            else
            {
                valuesDictionary["action"] = urlActionContext.Action;
            }

            if (urlActionContext.Controller == null)
            {
                if (!valuesDictionary.ContainsKey("controller") &&
                    AmbientValues.TryGetValue("controller", out var controller))
                {
                    valuesDictionary["controller"] = controller;
                }
            }
            else
            {
                valuesDictionary["controller"] = urlActionContext.Controller;
            }

            var endpoints = _routeValuesBasedEndpointFinder.FindEndpoints(
                new RouteValuesBasedEndpointFinderContext()
            {
                ExplicitValues = valuesDictionary,
                AmbientValues  = AmbientValues
            });

            var successfullyGeneratedLink = _linkGenerator.TryGetLink(
                ActionContext.HttpContext,
                endpoints,
                valuesDictionary,
                AmbientValues,
                out var link);

            if (!successfullyGeneratedLink)
            {
                //TODO: log here

                return(null);
            }

            return(GenerateUrl(urlActionContext.Protocol, urlActionContext.Host, link, urlActionContext.Fragment));
        }
        /// <inheritdoc />
        public virtual string Action(UrlActionContext actionContext)
        {
            if (actionContext == null)
            {
                throw new ArgumentNullException(nameof(actionContext));
            }

            actionContext.Values = AddApiVersionRouteValueIfNecessary(actionContext.Values);
            return(Url.Action(actionContext));
        }
Ejemplo n.º 3
0
        /// <inheritdoc />
        public override string Action(UrlActionContext actionContext)
        {
            if (actionContext == null)
            {
                throw new ArgumentNullException(nameof(actionContext));
            }

            var valuesDictionary = GetValuesDictionary(actionContext.Values);

            if (actionContext.Action == null)
            {
                if (!valuesDictionary.ContainsKey("action") &&
                    AmbientValues.TryGetValue("action", out object action))
                {
                    valuesDictionary["action"] = action;
                }
            }
            else
            {
                valuesDictionary["action"] = actionContext.Action;
            }

            if (actionContext.Controller == null)
            {
                if (!valuesDictionary.ContainsKey("controller") &&
                    AmbientValues.TryGetValue("controller", out object controller))
                {
                    valuesDictionary["controller"] = controller;
                }
            }
            else
            {
                valuesDictionary["controller"] = actionContext.Controller;
            }

            var pathData = GetVirtualPathData(routeName: null, values: valuesDictionary);

            if (pathData is AbsolutPathData)
            {
                var absolutePathData = pathData as AbsolutPathData;

                if (string.Equals(absolutePathData.Host, HttpContext.Request.Host.Value, StringComparison.CurrentCultureIgnoreCase) && absolutePathData.Protocol == HttpContext.Request.Scheme)
                {
                    return(GenerateUrl(null, null, pathData, actionContext.Fragment));
                }
                //we don't support changing protocol for subdomain
                return(GenerateUrl(absolutePathData.Protocol, absolutePathData.Host, pathData, actionContext.Fragment));
            }
            return(GenerateUrl(actionContext.Protocol, actionContext.Host, pathData, actionContext.Fragment));
        }
Ejemplo n.º 4
0
        /// <inheritdoc />
        public override string?Action(UrlActionContext actionContext)
        {
            if (actionContext == null)
            {
                throw new ArgumentNullException(nameof(actionContext));
            }

            var valuesDictionary = GetValuesDictionary(actionContext.Values);

            NormalizeRouteValuesForAction(actionContext.Action, actionContext.Controller, valuesDictionary, AmbientValues);

            var virtualPathData = GetVirtualPathData(routeName: null, values: valuesDictionary);

            return(GenerateUrl(actionContext.Protocol, actionContext.Host, virtualPathData, actionContext.Fragment));
        }
Ejemplo n.º 5
0
        public override string?Action(UrlActionContext urlActionContext)
        {
            if (urlActionContext == null)
            {
                throw new ArgumentNullException(nameof(urlActionContext));
            }

            var values = GetValuesDictionary(urlActionContext.Values);

            if (urlActionContext.Action == null)
            {
                if (!values.ContainsKey("action") &&
                    AmbientValues.TryGetValue("action", out var action))
                {
                    values["action"] = action;
                }
            }
            else
            {
                values["action"] = urlActionContext.Action;
            }

            if (urlActionContext.Controller == null)
            {
                if (!values.ContainsKey("controller") &&
                    AmbientValues.TryGetValue("controller", out var controller))
                {
                    values["controller"] = controller;
                }
            }
            else
            {
                values["controller"] = urlActionContext.Controller;
            }


            var path = _linkGenerator.GetPathByRouteValues(
                ActionContext.HttpContext,
                routeName: null,
                values,
                fragment: urlActionContext.Fragment == null ? FragmentString.Empty : new FragmentString("#" + urlActionContext.Fragment));

            return(GenerateUrl(urlActionContext.Protocol, urlActionContext.Host, path));
        }
Ejemplo n.º 6
0
        /// <inheritdoc />
        public virtual string Action(UrlActionContext actionContext)
        {
            if (actionContext == null)
            {
                throw new ArgumentNullException(nameof(actionContext));
            }

            var valuesDictionary = GetValuesDictionary(actionContext.Values);

            if (actionContext.Action == null)
            {
                object action;
                if (!valuesDictionary.ContainsKey("action") &&
                    AmbientValues.TryGetValue("action", out action))
                {
                    valuesDictionary["action"] = action;
                }
            }
            else
            {
                valuesDictionary["action"] = actionContext.Action;
            }

            if (actionContext.Controller == null)
            {
                object controller;
                if (!valuesDictionary.ContainsKey("controller") &&
                    AmbientValues.TryGetValue("controller", out controller))
                {
                    valuesDictionary["controller"] = controller;
                }
            }
            else
            {
                valuesDictionary["controller"] = actionContext.Controller;
            }

            var virtualPathData = GetVirtualPathData(routeName: null, values: valuesDictionary);

            return(GenerateUrl(actionContext.Protocol, actionContext.Host, virtualPathData, actionContext.Fragment));
        }
Ejemplo n.º 7
0
        public void UrlActionWithUrlActionContext_ReturnsExpectedResult()
        {
            // Arrange
            var urlHelper = CreateUrlHelperWithDefaultRoutes();

            var actionContext = new UrlActionContext()
            {
                Action     = "contact",
                Controller = "home3",
                Values     = new { id = "idone" },
                Protocol   = "ftp",
                Host       = "remotelyhost",
                Fragment   = "somefragment"
            };

            // Act
            var url = urlHelper.Action(actionContext);

            // Assert
            Assert.Equal("ftp://remotelyhost/app/home3/contact/idone#somefragment", url);
        }
Ejemplo n.º 8
0
        /// <inheritdoc />
        public virtual string Action(UrlActionContext actionContext)
        {
            if (actionContext == null)
            {
                throw new ArgumentNullException(nameof(actionContext));
            }

            var valuesDictionary = GetValuesDictionary(actionContext.Values);

            if (actionContext.Action == null)
            {
                object action;
                if (!valuesDictionary.ContainsKey("action") &&
                    AmbientValues.TryGetValue("action", out action))
                {
                    valuesDictionary["action"] = action;
                }
            }
            else
            {
                valuesDictionary["action"] = actionContext.Action;
            }

            if (actionContext.Controller == null)
            {
                object controller;
                if (!valuesDictionary.ContainsKey("controller") &&
                    AmbientValues.TryGetValue("controller", out controller))
                {
                    valuesDictionary["controller"] = controller;
                }
            }
            else
            {
                valuesDictionary["controller"] = actionContext.Controller;
            }

            var virtualPathData = GetVirtualPathData(routeName: null, values: valuesDictionary);
            return GenerateUrl(actionContext.Protocol, actionContext.Host, virtualPathData, actionContext.Fragment);
        }
Ejemplo n.º 9
0
 /// <inheritdoc />
 public abstract string Action(UrlActionContext actionContext);
Ejemplo n.º 10
0
 public override string Action(UrlActionContext actionContext)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 11
0
        public void UrlActionWithUrlActionContext_ReturnsExpectedResult()
        {
            // Arrange
            var services = CreateServices();
            var urlHelper = CreateUrlHelperWithRouteCollection(services, "/app");

            var actionContext = new UrlActionContext()
            {
                Action = "contact",
                Controller = "home3",
                Values = new { id = "idone" },
                Protocol = "ftp",
                Host = "remotelyhost",
                Fragment = "somefragment"
            };

            // Act
            var url = urlHelper.Action(actionContext);

            // Assert
            Assert.Equal("ftp://remotelyhost/app/home3/contact/idone#somefragment", url);
        }
Ejemplo n.º 12
0
 public string Action(UrlActionContext actionContext)
 {
     throw new NotImplementedException();
 }
 public string Action(UrlActionContext actionContext)
 {
     return null;
 }
Ejemplo n.º 14
0
 public override string Action(UrlActionContext actionContext)
 {
     return ConvertToLowercaseUrl(base.Action(actionContext));
 }