Пример #1
0
        public override Task RouteAsync(RouteContext context)
        {
            var host = context.HttpContext.Request.Host.Value;

            string foundHostname = GetHostname(host);

            if (foundHostname == null && Subdomain != null)
            {
                return(Task.CompletedTask);
            }

            if (Subdomain == null)
            {
                if (foundHostname != null)
                {
                    return(Task.CompletedTask);
                }

                return(base.RouteAsync(context));
            }

            var subdomain = host.Substring(0, host.IndexOf(GetHostname(host)) - 1);

            if (!IsParameterName(Subdomain) && subdomain.ToLower() != Subdomain.ToLower())
            {
                return(Task.CompletedTask);
            }

            var parsedTemplate = TemplateParser.Parse(Subdomain);

            //that's for overriding default for subdomain
            if (IsParameterName(Subdomain) &&
                Defaults.ContainsKey(ParameterNameFrom(Subdomain)) &&
                !context.RouteData.Values.ContainsKey(ParameterNameFrom(Subdomain)))
            {
                context.RouteData.Values.Add(ParameterNameFrom(Subdomain), subdomain);
            }

            if (IsParameterName(Subdomain) &&
                constraintsWithSubdomainConstraint.ContainsKey(ParameterNameFrom(Subdomain)))
            {
                if (!RouteConstraintMatcher.Match(
                        constraintsWithSubdomainConstraint,
                        new RouteValueDictionary
                {
                    { ParameterNameFrom(Subdomain), subdomain }
                },
                        context.HttpContext,
                        this,
                        RouteDirection.IncomingRequest,
                        context.HttpContext.RequestServices.GetRequiredService <ILoggerFactory>().CreateLogger(typeof(RouteConstraintMatcher).FullName)))
                {
                    return(Task.CompletedTask);
                }
            }


            return(base.RouteAsync(context));
        }
Пример #2
0
        public override Task RouteAsync(RouteContext context)
        {
            var host = context.HttpContext.Request.Host.Value;

            string foundHostname = GetHostname(host);

            if (foundHostname == null && Subdomain != null)
            {
                return(Task.CompletedTask);
            }

            if (Subdomain == null)
            {
                if (foundHostname != null)
                {
                    return(Task.CompletedTask);
                }

                return(base.RouteAsync(context));
            }

            var subdomain = host.Substring(0, host.IndexOf(GetHostname(host)) - 1);

            if (!IsParameterName(Subdomain) && subdomain.ToLower() != Subdomain.ToLower())
            {
                return(Task.CompletedTask);
            }

            //that's for overriding default for subdomain
            if (IsParameterName(Subdomain) &&
                Defaults.ContainsKey(ParameterNameFrom(Subdomain)) &&
                !context.RouteData.Values.ContainsKey(ParameterNameFrom(Subdomain)))
            {
                context.RouteData.Values.Add(ParameterNameFrom(Subdomain), subdomain);
            }

            return(base.RouteAsync(context));
        }